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

_run_strategy dispatches on the category and jumps into the corresponding workflow block.

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.resp_extra_usagectx.resp_extra_usagechat_object._di_resp.extra_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. 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} (or simple mode)
  • 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 eventsstep_intro/leave/iteration, tool_call/return
  • update_step tool — the agent can revise the plan mid-run

Full details: Advanced → Step Loop.

Other Built-in Strategies

StrategyCategoryUse case
HybridReActAgentStrategyagent-mixedMoE models; XML-style results (deprecated, removed in v0.14.0)
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 the template methods (_append_tool_result_to_context, _handle_error_append, _append_reasoning, ...).

Next

Data Layer — messages, memory and backends.

Apache 2.0 License