agent

package
v0.121.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

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

func TestEventPublisher_PublishToolExecutionCompleted

func TestEventPublisher_PublishToolExecutionCompleted(t *testing.T)

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,
	cfg *config.Config,
	conversationRepo domain.ConversationRepository,
	a2aAgentService domain.A2AAgentService,
	skillsService domain.SkillsService,
	messageQueue domain.MessageQueue,
	stateManager domain.StateManager,
	timeoutSeconds int,
	optimizer domain.ConversationOptimizer,
	bgRegistry domain.BackgroundTaskRegistry,
) *AgentServiceImpl

NewAgentService creates a new agent service with pre-configured client

func (*AgentServiceImpl) BuildSystemPrompt added in v0.117.0

func (s *AgentServiceImpl) BuildSystemPrompt() string

BuildSystemPrompt returns the system prompt a fresh session (turn 0) would send to the LLM. Exposed for the `infer debug agent system_prompt` command.

func (*AgentServiceImpl) CancelRequest

func (s *AgentServiceImpl) CancelRequest(requestID string) error

CancelRequest cancels an active request. Safe to call multiple times for the same requestID - subsequent calls are no-ops via sync.Once on the underlying sessionCancel. Returns nil even when the request is unknown, so the UI can fire it on every Esc press without surfacing spurious errors after the session has already torn down. The agent loop publishes ChatCompleteEvent{Cancelled:true} as the single cancel-completion signal; no separate CancelledEvent broadcast is needed.

func (*AgentServiceImpl) GetMetrics

func (s *AgentServiceImpl) GetMetrics(requestID string) *domain.ChatMetrics

GetMetrics returns metrics for a completed request

func (*AgentServiceImpl) Run

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/BlockingTools/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)
  • BlockingTools: Approval required but undeliverable (approval_behaviour=block); gated tools are rejected with a reason
  • 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,
	cfg *config.AgentConfig,
	ctx context.Context,
	req *domain.AgentRequest,
	conversation *[]sdk.Message,
	eventPublisher *eventPublisher,
	cancelChan <-chan struct{},
	provider string,
	model string,
	registry domain.BackgroundTaskRegistry,
) *EventDrivenAgent

NewEventDrivenAgent creates a new event-driven agent

func (*EventDrivenAgent) Events added in v0.109.8

func (a *EventDrivenAgent) Events() chan<- domain.AgentEvent

Events returns a send-only handle on the agent's internal event channel so external producers (e.g. the A2A task poller) can wake the loop when background work completes while the agent is idling.

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL