Skip to content
GitHub

Quickstart

Agent system for Lexigram — AI agents with tools, strategies, and execution.

Terminal window
uv add lexigram-ai-agents
import asyncio
from lexigram import Application
from lexigram.ai.agents import AgentBase, AgentConfig, tool
from lexigram.ai.agents import AgentsModule
from lexigram.contracts.ai import AgentExecutorProtocol
@tool
async def get_weather(city: str) -> str:
"""Get the current weather for a city."""
return f"Sunny, 22°C in {city}"
class WeatherAgent(AgentBase):
name = "weather_agent"
system_prompt = "You are a helpful weather assistant."
@property
def tools(self):
return [get_weather]
async def main():
config = AgentConfig(max_iterations=10, default_temperature=0.3)
async with Application.boot(
name="agent-demo",
modules=[AgentsModule.configure(config)],
) as app:
executor = await app.container.resolve(AgentExecutorProtocol)
result = await executor.run(
agent=WeatherAgent(),
message="What is the weather in Tokyo?",
)
if result.is_ok():
print(result.unwrap().message)
asyncio.run(main())
  1. @tool decorated a function — auto-generated its JSON schema for the LLM.
  2. AgentBase subclass declared identity, persona, and tools.
  3. AgentsModule.configure(config) wired AgentsProvider into the container.
  4. AgentExecutorProtocol resolved the executor from DI.
  5. executor.run() returned Result[AgentResponse, AgentError].