Skip to content

Defining Agents

from astromesh_adk import agent
@agent(name="assistant", model="openai/gpt-4o", description="General assistant")
async def assistant(ctx):
"""You are a helpful assistant."""
return None # Use default orchestration

The docstring becomes the system prompt. Return None to use the default orchestration pipeline, or use ctx.run_default() for pre/post processing.

from astromesh_adk import Agent, RunContext
class MyAgent(Agent):
name = "custom"
model = "ollama/llama3"
pattern = "plan_and_execute"
def system_prompt_fn(self, ctx: RunContext) -> str:
return f"You help {ctx.user_id}"
async def on_before_run(self, ctx: RunContext):
"""Called before execution."""
async def on_after_run(self, ctx: RunContext, result):
"""Called after execution."""
async def on_tool_call(self, ctx: RunContext, tool_name: str, args: dict):
"""Called before each tool call."""
ParameterTypeDescription
namestrAgent identifier
modelstrProvider/model (e.g., "openai/gpt-4o")
toolslistTools available to the agent
patternstrOrchestration: react, plan_and_execute, parallel, pipeline, supervisor, swarm
memorystr | dictMemory config (e.g., "sqlite")
guardrailsdictInput/output guardrails
fallback_modelstrFallback provider/model
routingstrRouting strategy