agent
agentic_ml.research.agent
¶
Build a Strands agent for a research run (requires the research extra).
AgentConfig
dataclass
¶
AgentConfig(
pin_first: int = 1,
preserve_recent_messages: int = 4,
summary_ratio: float = 0.3,
compression_threshold: float = 0.85,
offload_max_result_tokens: int = 1500,
offload_preview_tokens: int = 750,
)
Strands-specific knobs for the research agent's conversation manager and context offloader.
Kept separate from :class:~agentic_ml.core.engine.ResearchConfig, which must stay usable
without Strands installed.
pin_first
class-attribute
instance-attribute
¶
pin_first: int = 1
Number of messages at the very start of the conversation permanently protected from
summarization. Message 0 is always the kickoff prompt; message 1 (only if pin_first >= 2)
is the agent's first response. The system prompt is sent separately on every model call and
is never part of this managed history, so it needs no protection.
preserve_recent_messages
class-attribute
instance-attribute
¶
preserve_recent_messages: int = 4
Minimum number of most-recent messages the conversation manager always keeps uncompressed.
summary_ratio
class-attribute
instance-attribute
¶
summary_ratio: float = 0.3
Fraction of the older, non-pinned messages summarized whenever compression triggers.
compression_threshold
class-attribute
instance-attribute
¶
compression_threshold: float = 0.85
Fraction of the model's context window that triggers proactive summarization.
offload_max_result_tokens
class-attribute
instance-attribute
¶
offload_max_result_tokens: int = 1500
Tool results larger than this (estimated tokens) are truncated with a retrievable preview.
offload_preview_tokens
class-attribute
instance-attribute
¶
offload_preview_tokens: int = 750
Size of the truncated preview kept in place of an offloaded tool result.
build_session_manager
¶
build_session_manager(
ctx: ResearchContext,
) -> SnapshotSessionManager
Create the session manager that persists conversation state under the run's workspace.
Source code in src/agentic_ml/research/agent.py
51 52 53 54 55 56 57 58 | |
build_research_agent
¶
build_research_agent(
ctx: ResearchContext,
model: object,
session_manager: object,
)
Create a Strands Agent wired with the research tools and the composed prompt.
This reproduces what context_manager="auto" builds (a SummarizingConversationManager
with proactive compression plus a ContextOffloader truncating large tool results with a
retrievable preview), but tuned via ctx.agent_config (see :class:AgentConfig) — the
"auto" defaults (preserve_recent_messages=10) never let summarization act on the short
conversations a research run typically has (kickoff + a handful of tool calls; no system
message is ever part of this managed history), so it always failed with "insufficient
messages for summarization". session_manager persists/restores the conversation across
process restarts; see :func:build_session_manager.
Source code in src/agentic_ml/research/agent.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |