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 run the agent’s orchestration pattern, or return a string to answer directly without calling the model. (ctx.run_default() is not wired by the runner and raises.)

from astromesh_adk import Agent, RunContext
class MyAgent(Agent):
"""You are a planning assistant."""
name = "custom"
model = "ollama/llama3"
pattern = "plan_and_execute"
async def on_before_run(self, ctx: RunContext):
"""Called before execution."""
async def on_after_run(self, ctx: RunContext, result):
"""Called after execution."""

The class docstring is the system prompt. on_before_run and on_after_run are called by the runner; system_prompt_fn and on_tool_call exist on the base class but the runner does not call them yet.

ParameterTypeDescription
namestrAgent identifier
modelstrProvider/model (e.g., "openai/gpt-4o")
descriptionstrShown when the agent is used as a tool. Defaults to name
toolslistTools available to the agent
patternstrOrchestration: react (default), plan_and_execute, parallel_fan_out, pipeline. An unknown value falls back to react. supervisor, swarm and parallel are team patterns
max_iterationsintOrchestration iteration cap. Default 10
memorystr | dictConversational memory, built by the core factory — only redis is supported, with its URL: {"conversational": {"backend": "redis", "connection": {"url": "redis://..."}}} and the core redis extra. Any other backend makes the run raise
guardrailsdictInput/output guardrails
fallback_modelstrFallback provider/model
routingstrRouting strategy. Default cost_optimized
model_configdictExtra model parameters