Documentation
¶
Index ¶
- Constants
- func AdaptTool(t *agent.Tool) (tool.Tool, error)
- func AdaptToolWithTimeout(t *agent.Tool, timeout time.Duration) (tool.Tool, error)
- func ModelTokenBudget(modelName string) int
- type Agent
- func (a *Agent) ADKAgent() adk_agent.Agent
- func (a *Agent) Run(ctx context.Context, sessionID string, input string) iter.Seq2[*session.Event, error]
- func (a *Agent) RunAndCollect(ctx context.Context, sessionID, input string) (string, error)
- func (a *Agent) RunStreaming(ctx context.Context, sessionID, input string, onChunk ChunkCallback) (string, error)
- func (a *Agent) WithErrorFixProvider(p ErrorFixProvider) *Agent
- func (a *Agent) WithMaxTurns(n int) *Agent
- type AgentOption
- type ChunkCallback
- type ContextAwareModelAdapter
- func (m *ContextAwareModelAdapter) GenerateContent(ctx context.Context, req *model.LLMRequest, stream bool) iter.Seq2[*model.LLMResponse, error]
- func (m *ContextAwareModelAdapter) Name() string
- func (m *ContextAwareModelAdapter) WithGraphRAG(svc *graph.GraphRAGService) *ContextAwareModelAdapter
- func (m *ContextAwareModelAdapter) WithMemory(provider MemoryProvider) *ContextAwareModelAdapter
- func (m *ContextAwareModelAdapter) WithMemoryLimits(maxReflections, maxObservations int) *ContextAwareModelAdapter
- func (m *ContextAwareModelAdapter) WithMemoryTokenBudget(budget int) *ContextAwareModelAdapter
- func (m *ContextAwareModelAdapter) WithRAG(svc *embedding.RAGService, opts embedding.RetrieveOptions) *ContextAwareModelAdapter
- func (m *ContextAwareModelAdapter) WithRuntimeAdapter(adapter *RuntimeContextAdapter) *ContextAwareModelAdapter
- type ErrorFixProvider
- type EventsAdapter
- type MemoryProvider
- type ModelAdapter
- type PIIRedactingModelAdapter
- type RuntimeContextAdapter
- type SessionAdapter
- func (s *SessionAdapter) AppName() string
- func (s *SessionAdapter) Events() session.Events
- func (s *SessionAdapter) EventsWithTokenBudget(budget int) session.Events
- func (s *SessionAdapter) ID() string
- func (s *SessionAdapter) LastUpdateTime() time.Time
- func (s *SessionAdapter) State() session.State
- func (s *SessionAdapter) UserID() string
- type SessionServiceAdapter
- func (s *SessionServiceAdapter) AppendEvent(ctx context.Context, sess session.Session, evt *session.Event) error
- func (s *SessionServiceAdapter) Create(ctx context.Context, req *session.CreateRequest) (*session.CreateResponse, error)
- func (s *SessionServiceAdapter) Delete(ctx context.Context, req *session.DeleteRequest) error
- func (s *SessionServiceAdapter) Get(ctx context.Context, req *session.GetRequest) (*session.GetResponse, error)
- func (s *SessionServiceAdapter) List(ctx context.Context, req *session.ListRequest) (*session.ListResponse, error)
- func (s *SessionServiceAdapter) WithTokenBudget(budget int) *SessionServiceAdapter
- type StateAdapter
- type ToolRegistryAdapter
Constants ¶
const DefaultTokenBudget = 32000
DefaultTokenBudget is the token budget used when no explicit budget is provided.
Variables ¶
This section is empty.
Functions ¶
func AdaptToolWithTimeout ¶
AdaptToolWithTimeout converts an internal agent.Tool to an ADK tool.Tool with an enforced per-call timeout. If timeout <= 0, behaves like AdaptTool.
func ModelTokenBudget ¶
ModelTokenBudget returns an appropriate history token budget for the given model. It uses approximately 50-60% of each model family's context window, leaving room for system prompts, tool definitions, and generated output. Returns DefaultTokenBudget for unknown models.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent wraps the ADK runner for integration with Lango.
func NewAgent ¶
func NewAgent(ctx context.Context, tools []tool.Tool, mod model.LLM, systemPrompt string, store internal.Store, opts ...AgentOption) (*Agent, error)
NewAgent creates a new Agent instance.
func NewAgentFromADK ¶
func NewAgentFromADK(adkAgent adk_agent.Agent, store internal.Store, opts ...AgentOption) (*Agent, error)
NewAgentFromADK creates a Lango Agent wrapping a pre-built ADK agent. Used for multi-agent orchestration where the agent tree is built externally.
func (*Agent) Run ¶
func (a *Agent) Run(ctx context.Context, sessionID string, input string) iter.Seq2[*session.Event, error]
Run executes the agent for a given session and returns an event iterator. It enforces a maximum turn limit to prevent unbounded tool-calling loops.
func (*Agent) RunAndCollect ¶
RunAndCollect executes the agent and returns the full text response. If the agent encounters a "failed to find agent" error (hallucinated agent name), it sends a correction message and retries once.
func (*Agent) RunStreaming ¶
func (a *Agent) RunStreaming(ctx context.Context, sessionID, input string, onChunk ChunkCallback) (string, error)
RunStreaming executes the agent and streams partial text chunks via the callback. It returns the full accumulated response text for backward compatibility.
func (*Agent) WithErrorFixProvider ¶
func (a *Agent) WithErrorFixProvider(p ErrorFixProvider) *Agent
WithErrorFixProvider sets an optional provider for learning-based error correction. When set, the agent will attempt to apply known fixes on errors before giving up.
func (*Agent) WithMaxTurns ¶
WithMaxTurns sets the maximum number of tool-calling turns per run. Zero or negative values use the default (25).
type AgentOption ¶
type AgentOption func(*agentOptions)
AgentOption configures optional Agent behavior at construction time.
func WithAgentErrorFixProvider ¶
func WithAgentErrorFixProvider(p ErrorFixProvider) AgentOption
WithAgentErrorFixProvider sets a learning-based error correction provider.
func WithAgentMaxTurns ¶
func WithAgentMaxTurns(n int) AgentOption
WithAgentMaxTurns sets the maximum number of tool-calling turns per run.
func WithAgentTokenBudget ¶
func WithAgentTokenBudget(budget int) AgentOption
WithAgentTokenBudget sets the session history token budget. Use ModelTokenBudget(modelName) to derive an appropriate value.
type ChunkCallback ¶
type ChunkCallback func(chunk string)
ChunkCallback is called for each streaming text chunk during agent execution.
type ContextAwareModelAdapter ¶
type ContextAwareModelAdapter struct {
// contains filtered or unexported fields
}
ContextAwareModelAdapter wraps a ModelAdapter with context retrieval. Before each LLM call, it retrieves relevant knowledge and injects it into the system instruction.
func NewContextAwareModelAdapter ¶
func NewContextAwareModelAdapter( inner *ModelAdapter, retriever *knowledge.ContextRetriever, builder *prompt.Builder, logger *zap.SugaredLogger, ) *ContextAwareModelAdapter
NewContextAwareModelAdapter creates a context-aware model adapter. The builder is used to produce the base system prompt; dynamic context (knowledge, memory, RAG) is still appended at call time.
func (*ContextAwareModelAdapter) GenerateContent ¶
func (m *ContextAwareModelAdapter) GenerateContent(ctx context.Context, req *model.LLMRequest, stream bool) iter.Seq2[*model.LLMResponse, error]
GenerateContent retrieves context and injects an augmented system prompt before delegating to the inner adapter.
func (*ContextAwareModelAdapter) Name ¶
func (m *ContextAwareModelAdapter) Name() string
Name delegates to the inner adapter.
func (*ContextAwareModelAdapter) WithGraphRAG ¶
func (m *ContextAwareModelAdapter) WithGraphRAG(svc *graph.GraphRAGService) *ContextAwareModelAdapter
WithGraphRAG adds graph-enhanced RAG support. When set, graph expansion is performed on vector search results to discover structurally connected context.
func (*ContextAwareModelAdapter) WithMemory ¶
func (m *ContextAwareModelAdapter) WithMemory(provider MemoryProvider) *ContextAwareModelAdapter
WithMemory adds observational memory support to the adapter. The session key is resolved at call time from the request context via session.SessionKeyFromContext.
func (*ContextAwareModelAdapter) WithMemoryLimits ¶
func (m *ContextAwareModelAdapter) WithMemoryLimits(maxReflections, maxObservations int) *ContextAwareModelAdapter
WithMemoryLimits sets the maximum number of reflections and observations to include in the LLM context. Zero means unlimited (existing behavior).
func (*ContextAwareModelAdapter) WithMemoryTokenBudget ¶
func (m *ContextAwareModelAdapter) WithMemoryTokenBudget(budget int) *ContextAwareModelAdapter
WithMemoryTokenBudget sets the maximum token budget for the memory section injected into the system prompt. Reflections are prioritized first (higher information density), then observations fill the remaining budget. Zero means use default (4000 tokens).
func (*ContextAwareModelAdapter) WithRAG ¶
func (m *ContextAwareModelAdapter) WithRAG(svc *embedding.RAGService, opts embedding.RetrieveOptions) *ContextAwareModelAdapter
WithRAG adds RAG (retrieval-augmented generation) support.
func (*ContextAwareModelAdapter) WithRuntimeAdapter ¶
func (m *ContextAwareModelAdapter) WithRuntimeAdapter(adapter *RuntimeContextAdapter) *ContextAwareModelAdapter
WithRuntimeAdapter adds runtime context support to the adapter.
type ErrorFixProvider ¶
type ErrorFixProvider interface {
GetFixForError(ctx context.Context, toolName string, err error) (string, bool)
}
ErrorFixProvider returns a known fix for a tool error if one exists. Implemented by learning.Engine.
type EventsAdapter ¶
type EventsAdapter struct {
// contains filtered or unexported fields
}
EventsAdapter adapts internal history to adk events. Uses token-budget truncation: includes messages from most recent until the budget is exhausted. Truncated history and converted events are lazily cached for O(1) repeated access.
func (*EventsAdapter) At ¶
func (e *EventsAdapter) At(i int) *session.Event
At returns the i-th event. The full event list is built once on first call and cached, making subsequent At calls O(1) instead of O(n).
func (*EventsAdapter) Len ¶
func (e *EventsAdapter) Len() int
type MemoryProvider ¶
type MemoryProvider interface {
ListObservations(ctx context.Context, sessionKey string) ([]memory.Observation, error)
ListReflections(ctx context.Context, sessionKey string) ([]memory.Reflection, error)
ListRecentReflections(ctx context.Context, sessionKey string, limit int) ([]memory.Reflection, error)
ListRecentObservations(ctx context.Context, sessionKey string, limit int) ([]memory.Observation, error)
}
MemoryProvider retrieves observations and reflections for a session.
type ModelAdapter ¶
type ModelAdapter struct {
// contains filtered or unexported fields
}
func NewModelAdapter ¶
func NewModelAdapter(p provider.Provider, model string) *ModelAdapter
func (*ModelAdapter) GenerateContent ¶
func (m *ModelAdapter) GenerateContent(ctx context.Context, req *model.LLMRequest, stream bool) iter.Seq2[*model.LLMResponse, error]
func (*ModelAdapter) Name ¶
func (m *ModelAdapter) Name() string
type PIIRedactingModelAdapter ¶
type PIIRedactingModelAdapter struct {
// contains filtered or unexported fields
}
PIIRedactingModelAdapter wraps an LLM and redacts PII from user messages before forwarding them to the underlying model. It also scans tool results and model responses for known secret values.
func NewPIIRedactingModelAdapter ¶
func NewPIIRedactingModelAdapter( inner model.LLM, redactor *agent.PIIRedactor, scanner *agent.SecretScanner, ) *PIIRedactingModelAdapter
NewPIIRedactingModelAdapter creates a PII-redacting model adapter. If scanner is nil, output scanning is disabled.
func (*PIIRedactingModelAdapter) GenerateContent ¶
func (m *PIIRedactingModelAdapter) GenerateContent( ctx context.Context, req *model.LLMRequest, stream bool, ) iter.Seq2[*model.LLMResponse, error]
GenerateContent redacts PII from user messages, scans tool results for secrets, and wraps the response iterator to scan model output.
func (*PIIRedactingModelAdapter) Name ¶
func (m *PIIRedactingModelAdapter) Name() string
Name delegates to the inner adapter.
type RuntimeContextAdapter ¶
type RuntimeContextAdapter struct {
// contains filtered or unexported fields
}
RuntimeContextAdapter provides runtime session/system state.
func NewRuntimeContextAdapter ¶
func NewRuntimeContextAdapter(toolCount int, encryption, knowledgeEnabled, memoryEnabled bool) *RuntimeContextAdapter
NewRuntimeContextAdapter creates a RuntimeContextAdapter with static system info.
func (*RuntimeContextAdapter) GetRuntimeContext ¶
func (a *RuntimeContextAdapter) GetRuntimeContext() knowledge.RuntimeContext
GetRuntimeContext returns a snapshot of the current runtime context.
func (*RuntimeContextAdapter) SetSession ¶
func (a *RuntimeContextAdapter) SetSession(sessionKey string)
SetSession updates the session key and derives the channel type.
type SessionAdapter ¶
type SessionAdapter struct {
// contains filtered or unexported fields
}
SessionAdapter adapts internal.Session to adk.Session
func NewSessionAdapter ¶
func (*SessionAdapter) AppName ¶
func (s *SessionAdapter) AppName() string
func (*SessionAdapter) Events ¶
func (s *SessionAdapter) Events() session.Events
func (*SessionAdapter) EventsWithTokenBudget ¶
func (s *SessionAdapter) EventsWithTokenBudget(budget int) session.Events
EventsWithTokenBudget returns an EventsAdapter that uses token-budget truncation.
func (*SessionAdapter) ID ¶
func (s *SessionAdapter) ID() string
func (*SessionAdapter) LastUpdateTime ¶
func (s *SessionAdapter) LastUpdateTime() time.Time
func (*SessionAdapter) State ¶
func (s *SessionAdapter) State() session.State
func (*SessionAdapter) UserID ¶
func (s *SessionAdapter) UserID() string
type SessionServiceAdapter ¶
type SessionServiceAdapter struct {
// contains filtered or unexported fields
}
func NewSessionServiceAdapter ¶
func NewSessionServiceAdapter(store internal.Store, rootAgentName string) *SessionServiceAdapter
func (*SessionServiceAdapter) AppendEvent ¶
func (*SessionServiceAdapter) Create ¶
func (s *SessionServiceAdapter) Create(ctx context.Context, req *session.CreateRequest) (*session.CreateResponse, error)
func (*SessionServiceAdapter) Delete ¶
func (s *SessionServiceAdapter) Delete(ctx context.Context, req *session.DeleteRequest) error
func (*SessionServiceAdapter) Get ¶
func (s *SessionServiceAdapter) Get(ctx context.Context, req *session.GetRequest) (*session.GetResponse, error)
func (*SessionServiceAdapter) List ¶
func (s *SessionServiceAdapter) List(ctx context.Context, req *session.ListRequest) (*session.ListResponse, error)
func (*SessionServiceAdapter) WithTokenBudget ¶
func (s *SessionServiceAdapter) WithTokenBudget(budget int) *SessionServiceAdapter
WithTokenBudget sets the token budget for history truncation. Use ModelTokenBudget(modelName) to derive an appropriate budget from the model name.
type StateAdapter ¶
type StateAdapter struct {
// contains filtered or unexported fields
}
StateAdapter adapts internal.Session.Metadata to adk.State
type ToolRegistryAdapter ¶
type ToolRegistryAdapter struct {
// contains filtered or unexported fields
}
ToolRegistryAdapter adapts []*agent.Tool to knowledge.ToolRegistryProvider.
func NewToolRegistryAdapter ¶
func NewToolRegistryAdapter(tools []*agent.Tool) *ToolRegistryAdapter
NewToolRegistryAdapter creates a ToolRegistryAdapter from agent tools. The input slice is copied to prevent caller mutation.
func (*ToolRegistryAdapter) ListTools ¶
func (a *ToolRegistryAdapter) ListTools() []knowledge.ToolDescriptor
ListTools returns all available tools.
func (*ToolRegistryAdapter) SearchTools ¶
func (a *ToolRegistryAdapter) SearchTools(query string, limit int) []knowledge.ToolDescriptor
SearchTools returns tools whose name or description contains the query (case-insensitive).