Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

chore: files changed crates/openhuman-core/src/agent/session_host/builder/factory.rs,crates/openhuma

Steven Enamakelf1413473eff1
diff --git a/crates/openhuman-core/src/agent/session_host/builder/factory.rs b/crates/openhuman-core/src/agent/session_host/builder/factory.rs
index a27ab436ed..58c8768986 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/factory.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/factory.rs
@@ -954,30 +954,13 @@ impl OpenHumanSessionHost {
// `agent_harness_e2e` mock now serves SSE for streaming, so the crate-native
// streaming path is exercised end-to-end.
//
- // Issue #4868 — resolve the per-agent iteration cap. When a named
- // definition is present, its `effective_max_iterations()` (which honors
- // `iteration_policy = "extended"` -> 50, and the declared `max_iterations`
- // for strict agents) takes priority over the global
- // `config.agent.max_tool_iterations` (default 10). This is the single
- // shared resolution point that closes #4868 for every direct-invocation
- // path: flows_build, flows_discover, agent-node runtime, cron, MCP
- // server, etc. Falls back to the global default when there is no
- // definition for this agent_id.
+ // Issue #4868 / #6958 — resolve the per-agent iteration cap at its one
+ // shared resolution point (explicit override, then the definition's
+ // `effective_max_iterations()`, then the global default). See
+ // `iteration_cap::resolve_max_tool_iterations`.
let mut effective_agent_config = config.agent.clone();
- if let Some(def) = target_def {
- let def_cap = def.effective_max_iterations();
- log::info!(
- "[agent::builder] applying definition iteration cap for agent_id={}: \
- definition.max_iterations={} iteration_policy={:?} -> effective={} \
- (was global default {})",
- agent_id,
- def.max_iterations,
- def.iteration_policy,
- def_cap,
- config.agent.max_tool_iterations,
- );
- effective_agent_config.max_tool_iterations = def_cap;
- }
+ effective_agent_config.max_tool_iterations =
+ super::iteration_cap::resolve_max_tool_iterations(&config.agent, target_def);
// Host-first, so a host tool wins a name collision -- see
// `HostTurnTools::merge_into`, which owns that rule and why.
let (host_policy, withheld_tool_names) =
diff --git a/crates/openhuman-core/src/agent/session_host/builder/iteration_cap.rs b/crates/openhuman-core/src/agent/session_host/builder/iteration_cap.rs
index 0025d36cea..412996cfe2 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/iteration_cap.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/iteration_cap.rs
@@ -4,11 +4,53 @@ use crate::agent::harness::definition::AgentDefinition;
use crate::config::AgentConfig;
/// The tool-iteration cap a turn built from `agent` runs under.
+///
+/// In order of precedence:
+///
+/// 1. `agent.max_tool_iterations_override` (config or
+/// `OPENHUMAN_AGENT_MAX_TOOL_ITERATIONS`), when set and non-zero. It is the
+/// operator's explicit word and wins over any definition, up or down
+/// (#6958: the only way to lift the orchestrator was patching its
+/// `agent.toml`).
+/// 2. The definition's `effective_max_iterations()` (#4868), which honours
+/// `iteration_policy = "extended"`. It replaces the global default rather
+/// than being bounded by it, so a strict short-lived agent keeps its small
+/// cap and the orchestrator keeps its large one.
+/// 3. `agent.max_tool_iterations`, for a turn with no definition.
+///
+/// Every direct-invocation path (flows build/discover, agent nodes, cron, the
+/// MCP server, RPC and web chat) resolves its cap here through the session
+/// factory. Sub-agents spawned mid-turn resolve theirs in
+/// `subagent_host::ops::runner` from their own definitions.
pub(crate) fn resolve_max_tool_iterations(
agent: &AgentConfig,
def: Option<&AgentDefinition>,
) -> usize {
- def.map_or(agent.max_tool_iterations, AgentDefinition::effective_max_iterations)
+ if let Some(cap) = agent.max_tool_iterations_override.filter(|cap| *cap > 0) {
+ log::info!(
+ "[agent::builder] iteration cap from explicit override: {cap} \
+ (definition={:?} definition_cap={:?} global={})",
+ def.map(|d| d.id.as_str()),
+ def.map(AgentDefinition::effective_max_iterations),
+ agent.max_tool_iterations,
+ );
+ return cap;
+ }
+ match def {
+ Some(def) => {
+ let cap = def.effective_max_iterations();
+ log::info!(
+ "[agent::builder] iteration cap from definition agent_id={}: \
+ max_iterations={} iteration_policy={:?} -> {cap} (global default {})",
+ def.id,
+ def.max_iterations,
+ def.iteration_policy,
+ agent.max_tool_iterations,
+ );
+ cap
+ }
+ None => agent.max_tool_iterations,
+ }
}
#[cfg(test)]