AgentState

org.llm4s.agent.AgentState
See theAgentState companion class
object AgentState

Attributes

Companion
class
Graph
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
AgentState.type

Members list

Type members

Inherited and Abstract types

type MirroredElemLabels <: Tuple

The names of the product elements

The names of the product elements

Attributes

Inherited from:
Mirror
type MirroredLabel <: String

The name of the type

The name of the type

Attributes

Inherited from:
Mirror

Value members

Concrete methods

def fromJson(json: Value, tools: ToolRegistry): Result[AgentState]

Deserialize agent state from JSON.

Deserialize agent state from JSON.

Tools must be provided separately as they cannot be serialized.

Value parameters

json

The JSON representation

tools

The tool registry to use (must be provided by caller)

Attributes

Returns

Result containing the deserialized state or an error

def loadFromFile(path: String, tools: ToolRegistry): Result[AgentState]

Load state from file (convenience method).

Load state from file (convenience method).

This performs I/O and may fail with filesystem errors or parse errors.

Value parameters

path

File path to read from

tools

The tool registry to use (tools are not serialized)

Attributes

Returns

Result containing the loaded state or an error

def pruneConversation(state: AgentState, config: ContextWindowConfig, tokenCounter: Message => Int): AgentState

Prune conversation history based on configuration. Returns a new AgentState with pruned conversation.

Prune conversation history based on configuration. Returns a new AgentState with pruned conversation.

This is a pure function - it does not modify the input state.

Value parameters

config

Context window configuration

state

The current agent state

tokenCounter

Function to count tokens in messages (optional, uses simple heuristic by default)

Attributes

Returns

New state with pruned conversation

def saveToFile(state: AgentState, path: String): Result[Unit]

Save state to file (convenience method).

Save state to file (convenience method).

This performs I/O and may fail with filesystem errors.

Value parameters

path

File path to write to

state

The state to save

Attributes

Returns

Result indicating success or error

def toJson(state: AgentState): Value

Serialize agent state to JSON.

Serialize agent state to JSON.

Note: ToolRegistry is not serialized (contains function references). Tools must be re-registered when loading state.

Value parameters

state

The agent state to serialize

Attributes

Returns

JSON representation