Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
885d124
refactor(run_agent): extract message sanitization to agent/message_sa…
teknium1 May 17, 2026
59f1c0f
refactor(run_agent): extract tool-dispatch helpers to agent/tool_disp…
teknium1 May 17, 2026
5f309ae
refactor(run_agent): extract OpenAI proxy, safe stdio, IterationBudget
teknium1 May 17, 2026
1f6eb17
refactor(run_agent): extract background memory/skill review to agent/…
teknium1 May 17, 2026
5311d99
refactor(run_agent): extract context compression to agent/conversatio…
teknium1 May 17, 2026
2d2cd5e
refactor(run_agent): extract system-prompt builder to agent/system_pr…
teknium1 May 17, 2026
7955921
refactor(run_agent): extract tool execution to agent/tool_executor.py
teknium1 May 17, 2026
57f6762
refactor(run_agent): extract stream diagnostics to agent/stream_diag.py
teknium1 May 17, 2026
4b25619
refactor(run_agent): extract chat-completion helpers to agent/chat_co…
teknium1 May 17, 2026
0430e71
refactor(run_agent): extract streaming API caller (893 LOC) to agent/…
teknium1 May 17, 2026
c42fa94
refactor(run_agent): extract Codex runtime + assorted helpers to dedi…
teknium1 May 17, 2026
d35ee7b
refactor(run_agent): move review prompts to agent/background_review.py
teknium1 May 17, 2026
0530252
refactor(run_agent): extract run_conversation to agent/conversation_l…
teknium1 May 17, 2026
9f40898
refactor(run_agent): extract __init__ (1,381 LOC) to agent/agent_init.py
teknium1 May 17, 2026
94c3e0a
refactor(run_agent): extract 10 more helpers to agent/agent_runtime_h…
teknium1 May 17, 2026
4782379
refactor(run_agent): review fixes — keyword-forward __init__, drop de…
teknium1 May 17, 2026
152d42d
Merge origin/main into pr-27248 (resolving run_agent.py = ours)
teknium1 May 17, 2026
8f3bc17
feat(agent): Added gemma 4 to reasoning allowlist
matthewlai May 13, 2026
94b3131
fix(run_agent): detect kimi models via model name for reasoning pad
hermesagent26 May 17, 2026
a77ca92
perf(run_agent): accumulate length-continuation prefix via list+join
teknium1 May 17, 2026
7d221aa
fix(langfuse): complete observability fix — port to extracted convers…
teknium1 May 17, 2026
b07524e
feat(xai-oauth): add xAI Grok OAuth (SuperGrok Subscription) provider…
teknium1 May 17, 2026
27df249
feat(nvidia): add NIM billing origin header — port to extracted modules
teknium1 May 17, 2026
6362e71
fix(xai-oauth): recover from prelude SSE errors, gate reasoning repla…
teknium1 May 17, 2026
408aa4f
port(refactor): deepseek thinking-mode (068c24f8a + cd9470f41) — no n…
teknium1 May 17, 2026
6975a2d
fix(xai-oauth): entitlement-403 chain — final state (ce0e189d3 + 9818…
teknium1 May 17, 2026
f885be0
fix(auxiliary): resolve xai oauth compression from pool — port to con…
teknium1 May 17, 2026
fe4c87e
fix(agent): retry malformed anthropic stream parser errors — port to …
teknium1 May 17, 2026
3fbedd7
feat: add supports_parallel_tool_calls for MCP servers (#26825) — por…
teknium1 May 17, 2026
df22d29
fix(copilot): GitHub Models 413 hint — port to extracted conversation…
teknium1 May 17, 2026
80fa92a
fix(codex): rotate pool on usage limit 429 — port to extracted modules
teknium1 May 17, 2026
aa05ffb
fix(xai): surface provider 'error' SSE frame in Codex fallback stream…
teknium1 May 17, 2026
4ab9a06
fix(agent): reset _fallback_index at turn start even when no fallback…
teknium1 May 17, 2026
b5bcffe
fix(fallback): forward custom_providers to fallback model context-len…
teknium1 May 17, 2026
4ece521
fix(run_agent): isolate background review fork from external memory p…
teknium1 May 17, 2026
36ad833
fix(run_agent): guard memory provider init against empty/whitespace s…
teknium1 May 17, 2026
563b4d9
fix: strip image parts for non-vision models with provider profiles +…
teknium1 May 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,469 changes: 1,469 additions & 0 deletions agent/agent_init.py

Large diffs are not rendered by default.

2,134 changes: 2,134 additions & 0 deletions agent/agent_runtime_helpers.py

Large diffs are not rendered by default.

570 changes: 570 additions & 0 deletions agent/background_review.py

Large diffs are not rendered by default.

2,043 changes: 2,043 additions & 0 deletions agent/chat_completion_helpers.py

Large diffs are not rendered by default.

448 changes: 448 additions & 0 deletions agent/codex_runtime.py

Large diffs are not rendered by default.

556 changes: 556 additions & 0 deletions agent/conversation_compression.py

Large diffs are not rendered by default.

4,018 changes: 4,018 additions & 0 deletions agent/conversation_loop.py

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions agent/iteration_budget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""Per-agent iteration budget — thread-safe consume/refund counter.

Extracted from ``run_agent.py``. Each ``AIAgent`` instance (parent or
subagent) holds an :class:`IterationBudget`; the parent's cap comes from
``max_iterations`` (default 90), each subagent's cap comes from
``delegation.max_iterations`` (default 50).

``run_agent`` re-exports ``IterationBudget`` so existing
``from run_agent import IterationBudget`` imports keep working unchanged.
"""

from __future__ import annotations

import threading


class IterationBudget:
"""Thread-safe iteration counter for an agent.

Each agent (parent or subagent) gets its own ``IterationBudget``.
The parent's budget is capped at ``max_iterations`` (default 90).
Each subagent gets an independent budget capped at
``delegation.max_iterations`` (default 50) — this means total
iterations across parent + subagents can exceed the parent's cap.
Users control the per-subagent limit via ``delegation.max_iterations``
in config.yaml.

``execute_code`` (programmatic tool calling) iterations are refunded via
:meth:`refund` so they don't eat into the budget.
"""

def __init__(self, max_total: int):
self.max_total = max_total
self._used = 0
self._lock = threading.Lock()

def consume(self) -> bool:
"""Try to consume one iteration. Returns True if allowed."""
with self._lock:
if self._used >= self.max_total:
return False
self._used += 1
return True

def refund(self) -> None:
"""Give back one iteration (e.g. for execute_code turns)."""
with self._lock:
if self._used > 0:
self._used -= 1

@property
def used(self) -> int:
with self._lock:
return self._used

@property
def remaining(self) -> int:
with self._lock:
return max(0, self.max_total - self._used)


__all__ = ["IterationBudget"]
Loading
Loading