Skip to content
GitHub

AI Agents (lexigram-ai-agents)

Agent system for Lexigram Framework - AI agents with tools, strategies, and execution


Agent orchestration package for the Lexigram Framework. Provides agent base classes, tool registration, execution strategies (ReAct, Plan-and-Execute, Reflexion, Supervisor), observability, and multi-agent coordination — all wired through DI via AgentsModule. Zero-config usage starts with sensible defaults.

Full documentation: docs.lexigram.dev

Terminal window
uv add lexigram-ai-agents
from lexigram import Application
from lexigram.di.module import Module, module
from lexigram.ai.agents import AgentsModule
from lexigram.ai.agents.config import AgentConfig
from lexigram.ai.llm import LLMModule
@module(imports=[
LLMModule.stub(), # provides LLMClientProtocol
AgentsModule.configure(AgentConfig(max_iterations=10)),
])
class AppModule(Module):
pass
async with Application.boot(modules=[AppModule]) as app:
# use app.container to resolve services
...

Note: AgentsModule requires an LLM client (LLMClientProtocol) in the container — provided by LLMModule (from lexigram-ai-llm). When using a real LLM provider, set OPENAI_API_KEY (or configure your provider in ClientConfig).

Zero-config usage: Call AgentsModule.configure() with no arguments to use defaults.

application.yaml
ai_agents:
max_iterations: 10
default_temperature: 0.7
default_max_tokens: 2048
enable_tracing: true
Section titled “Option 2 — Profiles + Environment Variables (recommended)”
Terminal window
export LEX_AI_AGENTS__MAX_ITERATIONS=15
# Environment variables for each field
from lexigram.ai.agents.config import AgentConfig
from lexigram.ai.agents import AgentsModule
config = AgentConfig(max_iterations=10)
AgentsModule.configure(config)
FieldDefaultEnv varDescription
enabledTrueLEX_AI_AGENTS__ENABLEDEnable the agent subsystem
max_iterations10LEX_AI_AGENTS__MAX_ITERATIONSMaximum reasoning iterations per execution
default_temperature0.7LEX_AI_AGENTS__DEFAULT_TEMPERATUREDefault LLM temperature
default_max_tokens2048LEX_AI_AGENTS__DEFAULT_MAX_TOKENSDefault max tokens for LLM responses
tool_max_retries3LEX_AI_AGENTS__TOOL_MAX_RETRIESRetry attempts for transient tool errors
enable_tracingTrueLEX_AI_AGENTS__ENABLE_TRACINGEnable OpenTelemetry tracing
enable_metricsTrueLEX_AI_AGENTS__ENABLE_METRICSEnable Prometheus metrics
MethodDescription
AgentsModule.configure(config, enable_multi_agent)Configure with explicit config
AgentsModule.stub()Minimal config for testing
  • Agent base classes: AgentBase for defining agents with tools and system prompts
  • Execution strategies: ReAct, Plan-and-Execute, Reflexion, Supervisor
  • Tool system: @tool decorator for registering standalone tool functions
  • Multi-agent coordination: AgentAsToolAdapter for agent-to-agent delegation
  • Observability: Built-in tracing and metrics via AgentTracer and AgentMetrics
from lexigram.ai.llm import LLMModule
async with Application.boot(modules=[LLMModule.stub(), AgentsModule.stub()]) as app:
# your test code
...

AgentsModule.stub() alone fails container validation without an LLMClientProtocol in the container — pair it with LLMModule.stub() as shown.

FileWhat it contains
src/lexigram/ai/agents/module.pyAgentsModule.configure() and stub()
src/lexigram/ai/agents/config.pyAgentConfig and environment variable bindings
src/lexigram/ai/agents/agent/base.pyAgentBase class with tools and prompts
src/lexigram/ai/agents/executor/executor.pyAgentExecutorImpl — strategy execution loop
src/lexigram/ai/agents/tools/registry.pyToolRegistryImpl and @tool decorator
src/lexigram/ai/agents/strategies/react.pyReAct reasoning loop
src/lexigram/ai/agents/di/provider.pyAgentsProvider — registers agents into DI