Skip to content

refactor(runtime): run the agent loop on apodex-agent-core 0.12.0 - #50

Merged
zhanghanduo merged 2 commits into
mainfrom
refactor/agent-core-runtime
Sep 25, 2026
Merged

zhanghanduo merged 2 commits into
mainfrom
refactor/agent-core-runtime

Conversation

@zhanghanduo

@zhanghanduo zhanghanduo commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Replaces FrontierAgent's forked runtime engine with the published apodex-agent-core package (pinned ==0.12.0), following the ApodexHarness integration pattern. The core loop is now decoupled from workflows: frontier_agent.* keeps its import paths, so workflows/, apodex/ and benchmarks/ need no changes.

  • 80 modules → sys.modules aliases of their agent_core counterparts (loop contracts, messages, tools, compaction, observers, AgentBus pieces, DAG, registries, models, providers). This also unifies class identity and contextvars with the engine.
  • Product policy injected, not forked:
    • core/runtime/loop/agent_loop.py — AgentLoopHooks (sticky-session binding, execution scope, wall deadline, spill-file detection).
    • core/runtime/loop/tool_exec.py — ToolExecutionHooks (timeout floors, bash budget contextvar, usage metering, configurable result cap with spill, per-turn aggregate budget).
    • components/agent_bus/bus.py — configure_* resolvers so sub-agents get the same hooks, pause check and event sink.
    • infra/openai_client.py — session-affinity resolvers.
    • model-registry path, compaction prompt style and trigger ratio, ResourceManager role LLMs.
  • Kept local (product-only): config, providers, llm_adapter, summary_llm, scheduler, process manager, console / duplicate-query observers.
  • tools/check_symbols.py now follows sys.modules aliases and external star imports.

Behaviour changes (now follows AgentCore)

  • Compaction pins the first user message verbatim and replaces legacy prose spill indexes; KeepLastN writes mini cards.
  • Runaway recovery uses AgentCore's 3-stage ladder; landing turns block non-landing tool calls.
  • Any-typed tool params generate {"type": "string"} (deliberate upstream: strict validators reject untyped nodes) — create_file now annotates its rows / data shapes explicitly.
  • Tests that pinned fork internals (test_long_run_compaction, test_summary_retry_budget) now assert AgentCore semantics.

Upstream follow-ups (AgentCore)

Landed and released in 0.12.0, and the local workarounds are removed in this PR: ApodexAI/AgentCore#41 (empty api_key), #42 (TaskBoardObserver critical), #43 (public host helpers). Runaway-retry wording: ApodexAI/AgentCore#46. (Sub-agent result caps and fan-in protection turned out to be host-configurable already, via the AgentBus runtime spec's config_builder and TieredCompactor(protect_tool_names=...).)

Test plan

  • pytest tests — 895 passed, 4 skipped (same as main)
  • ruff, pyright (only pre-existing missing-extras errors), check_symbols.py, check_lazy_exports.py, import_smoke.py --stage 1
  • Re-run on 0.12.0: full suite 895 passed; real react coding + agent_team smoke ✅
  • Real smoke tests with apodex-1.1-mini, side by side with main (on 0.11.1):
    • react coding (fix + bash verify) ✅
    • react research (web_search / web_fetch / summary LLM) ✅
    • agent_team with parallel sub-agents via AgentBus ✅
  • Long run that triggers compaction / runaway recovery with a real model
  • Harbor benchmark adapter (harbor extra not installed locally)

🤖 Generated with Claude Code

Replace the forked runtime engine in frontier_agent/ with the published
apodex-agent-core package, following ApodexHarness's integration pattern.
frontier_agent.* keeps its import paths, so workflows, apodex and benchmarks
are unchanged:

- 80 modules become sys.modules aliases of their agent_core counterparts
  (loop contracts, messages, tools, compaction, observers, AgentBus pieces,
  DAG, registries, models, providers), which unifies class identity and
  contextvars with the engine.
- Product policy is injected instead of forked: AgentLoopHooks (session
  binding, execution scope, wall deadline, spill detection) and
  ToolExecutionHooks (timeout floors, bash budget, metering, result cap with
  spill, aggregate budget); configure_* resolvers for AgentBus and the
  OpenAI session-affinity policy; a model-registry path; compaction prompt
  style and trigger ratio.
- Product-only modules (config, providers, llm_adapter, summary_llm,
  scheduler, process_manager, console/duplicate-query observers) stay local
  on top of the shared types.
- tools/check_symbols.py follows sys.modules aliases and external star
  imports.
- Tests that pinned fork internals now assert AgentCore's semantics.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…unds

- Pin apodex-agent-core==0.12.0.
- infra/openai_client.py is a plain alias again (AgentCore treats an empty
  api_key as unset); only the session-affinity resolvers are configured.
- TaskBoardObserver aliases the shared class (now critical upstream).
- loop_types no longer hand re-exports wall_deadline_remaining_s (in
  __all__ upstream).
- create_file annotates its rows/data shorthand shapes explicitly instead of
  patching items to {}, so every schema node keeps a concrete type for
  strict validators.
- create_subagent uses the public bind_max_tokens instead of _ensure_bound.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@zhanghanduo zhanghanduo changed the title refactor(runtime): run the agent loop on apodex-agent-core 0.11.1 refactor(runtime): run the agent loop on apodex-agent-core 0.12.0 Sep 25, 2026

@dq-ai-dev dq-ai-dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed current head b456dd7. The AgentCore aliases preserve shared type and context identity, while the FrontierAgent hooks retain the product-specific session, execution, timeout, metering, spill, and AgentBus policies. The focused runtime checks and current CI are green. No blocking findings.

@zhanghanduo
zhanghanduo merged commit bbed073 into main Sep 25, 2026
5 checks passed
@zhanghanduo
zhanghanduo deleted the refactor/agent-core-runtime branch September 25, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants