This page covers the primary architectural components that implement the agent execution model, session management, and service infrastructure in the agent-swarm-kit system. For information about the public API functions like addAgent
, session
, and complete
, see Core API Functions. For details about the dependency injection container and service layering, see Service Architecture.
The agent execution engine consists of two primary components: ClientAgent
for message processing and AI completion, and ClientHistory
for conversation management.
ClientAgent
is the core execution engine that processes incoming messages, executes tool calls, and generates AI completions. It implements the IAgent
interface and serves as the primary orchestrator for agent behavior.
Key responsibilities:
execute()
methodrun()
method without history updatesThe ClientAgent
uses a queued execution model to prevent overlapping operations and maintains internal subjects for managing tool execution flow, agent changes, and output cancellation.
ClientHistory
manages conversation history for agents, providing filtered message arrays optimized for AI completion contexts and maintaining message persistence.
Key features:
keepMessages
parameterThe history system supports both raw message access and agent-optimized arrays that include system prompts and maintain tool call relationships for proper AI completion context.
ClientSession
orchestrates communication between clients, agents, and swarms while enforcing policies and managing message flows. It implements the ISession
interface and serves as the primary coordination layer.
Core capabilities:
The session maintains separation between stateful execution (with history updates) and stateless completion, while ensuring all communications pass through policy validation layers.
The service infrastructure provides the foundation for component lifecycle management, dependency injection, and API exposure through a layered architecture.
Connection services manage the instantiation and lifecycle of core components using memoization for efficient reuse.
Service responsibilities:
ClientAgent
instances with tool and completion dependenciesClientSession
with swarm and policy configurationsClientHistory
instances with storage adaptersClientSwarm
instances for agent navigation and coordinationEach connection service uses memoize
from functools-kit to cache instances by composite keys, ensuring efficient resource usage and consistent state management.
Public services provide the external API layer with context management and method scoping around connection services.
Public service features:
MethodContextService.runInContext()
for proper context managementPerfService
for execution monitoringThe public services layer provides a clean separation between external API and internal component management while ensuring consistent context propagation throughout the system.
The core components work together through a well-defined integration pattern that ensures proper message flow, state management, and error handling.
Integration patterns:
This architecture provides clear separation of concerns while maintaining efficient resource usage and proper state management across the entire system.