AIAgentGraphContext

class AIAgentGraphContext(val environment: AIAgentEnvironment, val agentInputType: KType, val agentInput: Any?, val config: AIAgentConfig, llm: AIAgentLLMContext, stateManager: AIAgentStateManager, storage: AIAgentStorage, val runId: String, val strategyName: String, val pipeline: AIAgentGraphPipeline, val agent: GraphAIAgent<*, *>, val parentContext: AIAgentGraphContextBase? = null) : AIAgentGraphContextBase(source)

Implements the AIAgentGraphContext interface, providing the context required for an AI agent's execution. This class encapsulates configurations, the execution pipeline, agent environment, and tools for handling agent lifecycles and interactions.

Parameters

environment

The AI agent environment responsible for tool execution and problem reporting.

agentInput

The input message to be used for the agent's interaction with the environment.

config

The configuration settings of the AI agent.

llm

The contextual data and execution utilities for the AI agent's interaction with LLMs.

stateManager

Manages the internal state of the AI agent.

storage

Concurrent-safe storage for managing key-value data across the agent's lifecycle.

runId

The unique identifier for the agent session.

strategyName

The identifier for the selected strategy in the agent's lifecycle.

pipeline

The AI agent pipeline responsible for coordinating AI agent execution and processing.

Constructors

Link copied to clipboard
constructor(environment: AIAgentEnvironment, agentInputType: KType, agentInput: Any?, config: AIAgentConfig, llm: AIAgentLLMContext, stateManager: AIAgentStateManager, storage: AIAgentStorage, runId: String, strategyName: String, pipeline: AIAgentGraphPipeline, agent: GraphAIAgent<*, *>, parentContext: AIAgentGraphContextBase? = null)

Creates an instance of the context with the given parameters.

Properties

Link copied to clipboard
open override val agent: GraphAIAgent<*, *>

Represents the AIAgent holding the current AIAgentContext.

Link copied to clipboard
open val agentId: String

A unique identifier representing the current agent instance within the context. The value is derived from the underlying agent.id.

Link copied to clipboard
open override val agentInput: Any?
Link copied to clipboard
open override val agentInputType: KType

KType representing the type of the agentInput

Link copied to clipboard
open override val config: AIAgentConfig
Link copied to clipboard
open override val environment: AIAgentEnvironment
Link copied to clipboard
open override val llm: AIAgentLLMContext

Represents the AI agent's LLM context, providing mechanisms for managing tools, prompts, and interaction with the execution environment. It ensures thread safety during concurrent read and write operations through the use of sessions.

Link copied to clipboard
open override val parentContext: AIAgentGraphContextBase? = null

Represents the parent context of the AI Agent.

Link copied to clipboard
open override val pipeline: AIAgentGraphPipeline
Link copied to clipboard
open override val runId: String
Link copied to clipboard

Manages and tracks the state of aт AI agent within the context of its execution.

Link copied to clipboard
open override val storage: AIAgentStorage

Concurrent-safe key-value storage for an agent, used to manage and persist data within the context of a the AI agent stage execution. The storage property provides a thread-safe mechanism for sharing and storing data specific to the agent's operation.

Link copied to clipboard
open override val strategyName: String

Functions

Link copied to clipboard
inline fun <T> AIAgentContext.agentInput(): T

Utility function to get AIAgentContext.agentInput and try to cast it to some expected type.

Link copied to clipboard
open fun copy(environment: AIAgentEnvironment = this.environment, agentInput: Any? = this.agentInput, agentInputType: KType = this.agentInputType, config: AIAgentConfig = this.config, llm: AIAgentLLMContext = this.llm, stateManager: AIAgentStateManager = this.stateManager, storage: AIAgentStorage = this.storage, runId: String = this.runId, strategyName: String = this.strategyName, pipeline: AIAgentGraphPipeline = this.pipeline): AIAgentGraphContextBase

Creates a copy of the current AIAgentGraphContext, allowing for selective overriding of its properties.

Link copied to clipboard

Creates a new instance of AIAgentContext with an updated list of tools, replacing the current tools in the LLM context with the provided list.

Link copied to clipboard

Retrieves a feature from the current context using the specified key.

open override fun <Feature : Any> feature(feature: AIAgentFeature<*, Feature>): Feature?

Retrieves an instance of the specified feature from the current context.

Link copied to clipboard

Retrieves a feature of the specified type from the context or throws an exception if it is not available.

Link copied to clipboard
open suspend override fun fork(): AIAgentGraphContextBase

Creates a copy of the current AIAgentGraphContext with deep copies of all mutable properties.

Link copied to clipboard
open override fun <T> get(key: AIAgentStorageKey<*>): T?

Retrieves data from the agent's storage using the specified key.

Link copied to clipboard

Retrieves the agent-specific context data associated with the current instance.

Link copied to clipboard
open suspend override fun getHistory(): List<Message>

Retrieves the history of messages exchanged during the agent's execution.

Link copied to clipboard
open override fun remove(key: AIAgentStorageKey<*>): Boolean

Removes a feature or data associated with the specified key from the agent's storage.

Link copied to clipboard

Removes the agent-specific context data associated with the current context.

Link copied to clipboard
open suspend override fun replace(context: AIAgentContext)

Replaces the current context with the provided context. This method is used to update the current context with values from another context, particularly useful in scenarios like parallel node execution where contexts need to be merged.

Link copied to clipboard

Provides the root context of the current agent. If the root context is not defined, this function defaults to returning the current instance.

Link copied to clipboard
open override fun store(key: AIAgentStorageKey<*>, value: Any)

Stores a feature in the agent's storage using the specified key.

Link copied to clipboard

Stores the given agent context data within the current AI agent context.