Skip to content

Agent Strategy ​

The Strategy Contract ​

A strategy implements the AgentStrategy ABC (or StrategyLikedObject for stateful instances) and declares a category via get_category():

CategoryExecutionFramework's role
agent / agent-mixedsingle_execute() per roundFramework runs the loop
rag / workflowrun() onceStrategy 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:

PropertyResolves fromFallback
self.presetctx.presetchat_object.preset
self.configctx.configchat_object.config
self.io_streamctx.io_streamchat_object.io_stream
self.train_contentctx.train_contentchat_object.train.content
self.stream_idctx.stream_idchat_object.stream_id
self.usagectx.usagechat_object._di_resp.usage, else None

self.usage is the run-scoped SessionUsageProxy ledger. It covers workflow-internal usage (strategy tool rounds plus auxiliary calls); the final completion's usage lives on resp.response.usage.

chat_object is the lifecycle-manager handle — the core reference, not a deprecated path. Prefer DI fields; fall back to chat_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. ChatObject defaults to _workflow_rendered, whose agent branch is the legacy single-call loop (AGENT_BLOCK) — one single_execute per round, no DAG decomposition; pass workflow=_step_workflow_rendered (or SIMPLE_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_calls while the request itself declares no tools is 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_choice stays auto. Native-thinking providers reject forced values, so required is 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 ​

StrategyCategoryUse case
NoActionAgentStrategyworkflowSkip tool calling entirely

Writing a Custom Strategy ​

python
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.

Apache 2.0 License