agent

package
v0.2.21 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2025 License: Apache-2.0 Imports: 49 Imported by: 0

Documentation

Overview

Package agent coordinates an agent turn across multiple responsibilities

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureGenerateOptions added in v0.2.1

func EnsureGenerateOptions(ctx context.Context, i *core.GenerateInput, agent *agent.Agent)

Types

type ChainContext added in v0.2.2

type ChainContext struct {
	Agent        *agentmdl.Agent
	Conversation *apiconv.Conversation
	Context      map[string]interface{}
	UserID       string
	ParentTurn   *memory.TurnMeta
	Output       struct{ Content, Model, MessageID, Error string }
	// Per-request controls
	AllowedChains []string
	DisableChains bool
}

func NewChainContext added in v0.2.2

func NewChainContext(in *QueryInput, out *QueryOutput, turn *memory.TurnMeta) ChainContext

NewChainContext builds a ChainContext from the current turn context, parent input and output. Conversation can be attached by the caller.

type ConversationMetadata

type ConversationMetadata struct {
	Tools   []string                   `json:"tools,omitempty"`
	Context map[string]interface{}     `json:"context,omitempty"`
	Extra   map[string]json.RawMessage `json:"-"`
}

ConversationMetadata is a typed representation of conversation metadata. It preserves unknown fields during round trips.

func (ConversationMetadata) MarshalJSON

func (m ConversationMetadata) MarshalJSON() ([]byte, error)

func (*ConversationMetadata) UnmarshalJSON

func (m *ConversationMetadata) UnmarshalJSON(data []byte) error

type Option

type Option func(*Service)

Option customises Service instances.

func WithCancelRegistry

func WithCancelRegistry(reg cancels.Registry) Option

WithCancelRegistry injects a registry to register per-turn cancel functions when executing Agent.Query. When nil, cancel registration is skipped.

func WithElicitationRouter

func WithElicitationRouter(r elicrouter.ElicitationRouter) Option

WithElicitationRouter injects a router to coordinate elicitation waits for assistant-originated prompts. When set, the agent will register a waiter and block until the HTTP/UI handler completes the elicitation.

func WithMCPManager added in v0.2.2

func WithMCPManager(m *mcpmgr.Manager) Option

WithMCPManager attaches an MCP Manager to resolve resources via MCP servers.

func WithNewElicitationAwaiter

func WithNewElicitationAwaiter(newAwaiter func() elicitation.Awaiter) Option

WithNewElicitationAwaiter configures a local awaiter used to resolve assistant-originated elicitations in interactive environments (CLI).

type QueryInput

type QueryInput struct {
	RequestTime time.Time `json:"requestTime,omitempty"`

	// ConversationID is an optional identifier for the conversation session.
	// If provided, conversation history will be tracked and reused.
	ConversationID       string `json:"conversationId,omitempty"`
	ParentConversationID string `json:"parentConversationId,omitempty"`
	// Optional client-supplied identifier for the user message. When empty the
	// service will generate a UUID.
	MessageID   string               `json:"messageId,omitempty"`
	AgentID     string               `json:"agentId"` // Agent ID to use
	UserId      string               `json:"userId"`
	Agent       *agentmdl.Agent      `json:"agent"` // Agent to use (alternative to agentId)
	Query       string               `json:"query"` // The query to submit
	Attachments []*prompt.Attachment `json:"attachments,omitempty"`

	MaxResponseSize int    `json:"maxResponseSize"` // Maximum size of the response in bytes
	MaxDocuments    int    `json:"maxDocuments"`    // Maximum number of documents to retrieve
	IncludeFile     bool   `json:"includeFile"`     // Whether to include complete file content
	EmbeddingModel  string `json:"embeddingModel"`  // Find to use for embeddings

	// Optional runtime overrides (single-turn)
	ModelOverride string                 `json:"model,omitempty"` // llm model name
	ToolsAllowed  []string               `json:"tools,omitempty"` // allow-list for tools (empty = default)
	Context       map[string]interface{} `json:"context,omitempty"`

	Transcript conversation.Transcript `json:"transcript,omitempty"`

	// ElicitationMode controls how missing-input requests are handled.
	ElicitationMode string `json:"elicitationMode,omitempty" yaml:"elicitationMode,omitempty"`

	AutoSummarize *bool `json:"autoSummarize,omitempty"`

	AllowedChains []string `json:"allowedChains,omitempty"` //

	DisableChains bool `json:"disableChains,omitempty"`

	ToolCallExposure *agentmdl.ToolCallExposure `json:"toolCallExposure,omitempty"`

	// ReasoningEffort optionally overrides agent-level Reasoning.Effort for this turn.
	// Valid values (OpenAI o-series): low | medium | high.
	ReasoningEffort *string `json:"reasoningEffort,omitempty"`
}

QueryInput represents the input for querying an agent's knowledge

func (*QueryInput) Actor added in v0.2.2

func (i *QueryInput) Actor() string

func (*QueryInput) ShallAutoSummarize added in v0.2.2

func (i *QueryInput) ShallAutoSummarize() bool

type QueryOutput

type QueryOutput struct {
	ConversationID string            `json:"conversationId,omitempty"`
	Agent          *agentmdl.Agent   `json:"agent"`                 // Agent used for the query
	Content        string            `json:"content"`               // Generated content from the agent
	Elicitation    *plan.Elicitation `json:"elicitation,omitempty"` // structured missing input request
	Plan           *plan.Plan        `json:"plan,omitempty"`        // current execution plan (optional)
	Usage          *usage.Aggregator `json:"usage,omitempty"`
	Model          string            `json:"model,omitempty"`
	MessageID      string            `json:"messageId,omitempty"`
	Warnings       []string          `json:"warnings,omitempty"`
}

QueryOutput represents the result of an agent knowledge query

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(llm *core.Service, agentFinder agent.Finder, augmenter *augmenter.Service, registry tool.Registry,
	defaults *config.Defaults,
	convClient apiconv.Client,

	opts ...Option) *Service

New creates a new agent service instance with the given tool registry.

func (*Service) BuildBinding

func (s *Service) BuildBinding(ctx context.Context, input *QueryInput) (*prompt.Binding, error)

func (*Service) BuildHistory added in v0.2.2

func (s *Service) BuildHistory(ctx context.Context, transcript apiconv.Transcript, binding *prompt.Binding) error

func (*Service) Finder added in v0.2.1

func (s *Service) Finder() agent.Finder

func (*Service) Method

func (s *Service) Method(name string) (svc.Executable, error)

Method returns the specified method

func (*Service) Methods

func (s *Service) Methods() svc.Signatures

Methods returns the service methods

func (*Service) Name

func (s *Service) Name() string

Name returns the service name

func (*Service) Query

func (s *Service) Query(ctx context.Context, input *QueryInput, output *QueryOutput) error

Query executes a query against an agent.

func (*Service) Summarize added in v0.2.2

func (s *Service) Summarize(ctx context.Context, conv *apiconv.Conversation) error

Jump to

Keyboard shortcuts

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