Agent Strategy
The Strategy Contract
A strategy implements the AgentStrategy ABC (or StrategyLikedObject for stateful instances) and declares a category via get_category():
| Category | Execution | Framework's role |
|---|---|---|
agent / agent-mixed | single_execute() per round | Framework runs the loop |
rag / workflow | run() once | Strategy has full control |
Dispatch is workflow control flow, not Python: _prepare_strategy only builds the StrategyContext, then two guarded branches pick the execution shape — NATIVE_IF(is_agent_category, ...) runs the framework loop, and NATIVE_IF(not_agent_category, RUN_INLINE_STRATEGY) calls run() once. Each branch is skipped when its predicate is false, so no category can execute twice (see Workflow Engine).
Resource Access via DI
Strategies never reach through ChatObject for resources — _StrategyBase exposes convenience properties that resolve from StrategyContext DI fields, falling back to chat_object:
| Property | Resolves from | Fallback |
|---|---|---|
self.preset | ctx.preset | chat_object.preset |
self.config | ctx.config | chat_object.config |
self.io_stream | ctx.io_stream | chat_object.io_stream |
self.train_content | ctx.train_content | chat_object.train.content |
self.stream_id | ctx.stream_id | chat_object.stream_id |
self.usage | ctx.usage | chat_object._di_resp.usage, else None |
self.usageis the run-scopedSessionUsageProxyledger. It covers workflow-internal usage (strategy tool rounds plus auxiliary calls); the final completion's usage lives onresp.response.usage.
chat_objectis the lifecycle-manager handle — the core reference, not a deprecated path. Prefer DI fields; fall back tochat_object.
The Built-in Step-Driven ReAct Strategy
ReActAgentStrategy (category agent-mixed) is the default strategy class. Its execution is node-driven: the LLM decides whether to decompose the task into a semantic DAG; the framework walks the DAG in topological order, one Step per node.
intro_step -> [NATIVE_WHILE: single_execute -> after_iteration] -> leave_step- decompose — LLM returns
{needs_decomposition, dag, reason}. SIMPLE mode (needs_decomposition=false) is still ReAct — the normal tool loop runs; it is just not step-driven (no DAG decomposition). Routine questions and simple tasks are assigned to this mode by default. - Step — one DAG node; may span multiple tool rounds
- stall detection — repeated identical signatures -> give-up prompt + cancel
- summarize — each Step ends with a subject-predicate summary (event-overridable)
- lifecycle events —
step_intro/leave/iteration,tool_call/return - update_step tool — the agent can revise the plan mid-run
Opt-in workflow. The strategy class is the default, but the Step loop only runs when the step-loop workflow is active.
ChatObjectdefaults to_workflow_rendered, whose agent branch is the legacy single-call loop (AGENT_BLOCK) — onesingle_executeper round, no DAG decomposition; passworkflow=_step_workflow_rendered(orSIMPLE_STEP_REACT) to enable the loop above. See ChatObject and Advanced -> Step Loop.
Full details: Advanced -> Step Loop.
The Agentic Call Path
A strategy does not have to ask for tool calls and for text in two separate requests. When the preset enables native thinking and its protocol adapter implements agentic_call_api(), the built-in ReAct strategy takes the agentic path: every round is a single request that streams the model's text as it is produced and hands back that round's tool calls at the end.
Three properties matter:
- Tools stay declared on every request. The tool definitions ride along on each round, including the one that produces the final answer. A request whose history carries
tool_callswhile the request itself declares notoolsis what makes a provider either reject the payload or let the model write the call out as plain text instead of a structured call. - The round that returns no tool calls is the final answer. Its content has already been streamed, and the workflow skips the separate tool-less completion. No second request is made to produce the reply.
tool_choicestaysauto. Native-thinking providers reject forced values, sorequiredis downgraded before it is sent.
When the adapter cannot do it, or thinking is off, the strategy keeps the legacy path: a tool round through tools_caller() followed by a separate completion. That combination logs a warning, because the last request on that path carries no tool definitions.
Other Built-in Strategies
| Strategy | Category | Use case |
|---|---|---|
NoActionAgentStrategy | workflow | Skip tool calling entirely |
Writing a Custom Strategy
from amrita_core.agent.strategy import AgentStrategy
from typing import Literal
class MyStrategy(AgentStrategy):
async def single_execute(self) -> bool:
# One tool round. Return True to continue, False to stop.
return True
async def on_post_process(self) -> None:
pass # after the loop
@classmethod
def get_category(cls) -> Literal["agent"]:
return "agent"For ReAct-style strategies, extend BaseReActAgentStrategy instead and override _append_reasoning (the only abstract method); _append_tool_results_batch and _handle_error_append are overridable but ship with working defaults.
Next
Data Layer — messages, memory and backends.
