Documentation
¶
Index ¶
- func NewAgentStateMachine(stateManager domain.StateManager) domain.AgentStateMachine
- func TestEventPublisher_PublishToolExecutionCompleted(t *testing.T)
- type AgentServiceImpl
- func (s *AgentServiceImpl) CancelRequest(requestID string) error
- func (s *AgentServiceImpl) GetMetrics(requestID string) *domain.ChatMetrics
- func (s *AgentServiceImpl) Run(ctx context.Context, req *domain.AgentRequest) (*domain.ChatSyncResponse, error)
- func (s *AgentServiceImpl) RunWithStream(ctx context.Context, req *domain.AgentRequest) (<-chan domain.ChatEvent, error)
- type AgentStateMachineImpl
- func (sm *AgentStateMachineImpl) CanTransition(ctx *domain.AgentContext, targetState domain.AgentExecutionState) bool
- func (sm *AgentStateMachineImpl) GetCurrentState() domain.AgentExecutionState
- func (sm *AgentStateMachineImpl) GetPreviousState() domain.AgentExecutionState
- func (sm *AgentStateMachineImpl) GetValidTransitions(ctx *domain.AgentContext) []domain.AgentExecutionState
- func (sm *AgentStateMachineImpl) Reset()
- func (sm *AgentStateMachineImpl) Transition(ctx *domain.AgentContext, targetState domain.AgentExecutionState) error
- type EventDrivenAgent
- type IndexedToolResult
- type StateTransition
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewAgentStateMachine ¶
func NewAgentStateMachine(stateManager domain.StateManager) domain.AgentStateMachine
NewAgentStateMachine creates a new agent state machine
Types ¶
type AgentServiceImpl ¶
type AgentServiceImpl struct {
// contains filtered or unexported fields
}
AgentServiceImpl implements the AgentService interface with direct chat functionality
func NewAgent ¶
func NewAgent( client domain.SDKClient, toolService domain.ToolService, config domain.ConfigService, conversationRepo domain.ConversationRepository, a2aAgentService domain.A2AAgentService, messageQueue domain.MessageQueue, stateManager domain.StateManager, timeoutSeconds int, optimizer domain.ConversationOptimizer, ) *AgentServiceImpl
NewAgentService creates a new agent service with pre-configured client
func (*AgentServiceImpl) CancelRequest ¶
func (s *AgentServiceImpl) CancelRequest(requestID string) error
CancelRequest cancels an active request
func (*AgentServiceImpl) GetMetrics ¶
func (s *AgentServiceImpl) GetMetrics(requestID string) *domain.ChatMetrics
GetMetrics returns metrics for a completed request
func (*AgentServiceImpl) Run ¶
func (s *AgentServiceImpl) Run(ctx context.Context, req *domain.AgentRequest) (*domain.ChatSyncResponse, error)
Run executes an agent task synchronously (for background/batch processing)
func (*AgentServiceImpl) RunWithStream ¶
func (s *AgentServiceImpl) RunWithStream(ctx context.Context, req *domain.AgentRequest) (<-chan domain.ChatEvent, error)
RunWithStream executes an agent task with streaming (for interactive chat)
type AgentStateMachineImpl ¶
type AgentStateMachineImpl struct {
// contains filtered or unexported fields
}
AgentStateMachineImpl implements the AgentStateMachine interface.
The state machine manages the agent's execution flow through the following states:
State Flow:
Idle → CheckingQueue → StreamingLLM → PostStream → EvaluatingTools → ApprovingTools/ExecutingTools → PostToolExecution → CheckingQueue (loop) → Completing → Idle
State Descriptions:
- Idle: Agent is not executing, waiting for work
- CheckingQueue: Checking if there are queued messages or if completion criteria are met
- StreamingLLM: Streaming responses from the LLM
- PostStream: Processing LLM response, checking for tool calls or completion
- EvaluatingTools: Determining if tool calls need approval
- ApprovingTools: Waiting for user approval of tool calls (only in chat mode)
- ExecutingTools: Executing approved or auto-approved tool calls
- PostToolExecution: Processing tool results, checking for completion or continuing
- Completing: Finalizing the agent execution
- Error: An error occurred during execution
- Cancelled: User cancelled the execution
- Stopped: Tool execution indicated stop (user rejection or error)
Thread Safety:
All state transitions are protected by a read-write mutex to ensure thread-safe access.
func (*AgentStateMachineImpl) CanTransition ¶
func (sm *AgentStateMachineImpl) CanTransition(ctx *domain.AgentContext, targetState domain.AgentExecutionState) bool
CanTransition checks if a transition from current state to target state is valid This is useful for checking before attempting a transition
func (*AgentStateMachineImpl) GetCurrentState ¶
func (sm *AgentStateMachineImpl) GetCurrentState() domain.AgentExecutionState
GetCurrentState returns the current state (thread-safe)
func (*AgentStateMachineImpl) GetPreviousState ¶
func (sm *AgentStateMachineImpl) GetPreviousState() domain.AgentExecutionState
GetPreviousState returns the previous state (thread-safe)
func (*AgentStateMachineImpl) GetValidTransitions ¶
func (sm *AgentStateMachineImpl) GetValidTransitions(ctx *domain.AgentContext) []domain.AgentExecutionState
GetValidTransitions returns all valid transitions from the current state
func (*AgentStateMachineImpl) Reset ¶
func (sm *AgentStateMachineImpl) Reset()
Reset resets the state machine to idle
func (*AgentStateMachineImpl) Transition ¶
func (sm *AgentStateMachineImpl) Transition(ctx *domain.AgentContext, targetState domain.AgentExecutionState) error
Transition attempts to transition to the target state
type EventDrivenAgent ¶
type EventDrivenAgent struct {
// contains filtered or unexported fields
}
EventDrivenAgent manages agent execution using event-driven state machine
func NewEventDrivenAgent ¶
func NewEventDrivenAgent( service *AgentServiceImpl, ctx context.Context, req *domain.AgentRequest, conversation *[]sdk.Message, eventPublisher *eventPublisher, cancelChan <-chan struct{}, provider string, model string, taskTracker domain.TaskTracker, ) *EventDrivenAgent
NewEventDrivenAgent creates a new event-driven agent
func (*EventDrivenAgent) Start ¶
func (a *EventDrivenAgent) Start()
Start begins the event-driven agent execution
func (*EventDrivenAgent) Wait ¶
func (a *EventDrivenAgent) Wait()
Wait waits for the agent to complete
type IndexedToolResult ¶
type IndexedToolResult struct {
Index int
Result domain.ConversationEntry
}
type StateTransition ¶
type StateTransition struct {
// contains filtered or unexported fields
}
StateTransition represents a state transition with guard and action