Skip to content

Feat/agon everywhere#235

Merged
cukas merged 4 commits into
mainfrom
feat/agon-everywhere
Jun 24, 2026
Merged

Feat/agon everywhere#235
cukas merged 4 commits into
mainfrom
feat/agon-everywhere

Conversation

@cukas

@cukas cukas commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

No description provided.

KERN-Agon and others added 4 commits June 24, 2026 17:47
The served browser brain (AgenticTurnBrainClient) drove every engine over a TEXT-MARKER protocol — the model had to TYPE `__AGON_TOOL__ {json}` as plain text. The API-only coding-plan engines (glm-5.2/kimi-k2p7/minimax-m3) routinely forgot to, narrating then stopping ("it stops") or flailing. The fix moves them onto NATIVE function-calling, which already existed at the dispatch layer (apiStreamDispatchWithHistory streams structured tool_call parts) but the brain never used.

- core: new apiDispatchTools — non-streaming wrapper that drives apiStreamDispatchWithHistory with a tools[] array and returns the DispatchResult (with structured .parts); disposes the generator on early throw.
- core: DispatchOptions.tools? (OpenAI-function shape), used only on the API path.
- adapter-cli: the binary-less API branch routes to apiDispatchTools when tools are present; CLI/companion paths are untouched, so claude/codex keep the marker.
- cli brain: capsToNativeTools (validates names against ^[a-zA-Z0-9_-]{1,64}$ so one bad name can't poison the whole request) + extractNativeToolCall; the loop offers tools every dispatch and reads result.parts FIRST, falling back to the marker. Call extraction runs before the no-answer guard so a native tool-only turn with empty stdout is never misread.

Verified: a live smoke test against all three coding-plan endpoints returned valid native tool_calls (zai/kimi/minimax). Transport-agnostic loop; CLI engines unchanged. +12 unit tests (49 total green). 6-engine agon review pass; needs-check findings fixed.

⚔️ Forged by [Agon](https://github.com/KERNlang/agon)

Co-Authored-By: agon (KERN) <292465531+KERN-Agon@users.noreply.github.com>
…er brain

Phase 2 of native function-calling. The API+tools path was sending the whole ReAct progress as one flat user-prompt transcript each step (re-grown every turn). Now the brain reconstructs a real OpenAI assistant/tool conversation thread from its step log: user(goal) then per executed step an assistant{tool_calls} + tool{result} pair (reminders become user instructions). The model attends to a genuine tool conversation instead of prose-about-tools, and the stable prefix is prompt-cacheable.

- core: apiDispatchToolsHistory (drives apiStreamDispatchWithHistory over a full message thread, optional system prepend, disposes the stream on throw); apiDispatchTools now delegates to it. Aligned both tool-aware dispatchers to a (..., tools?, systemPrompt?) tail so the optional args never silently swap.
- core: DispatchOptions.messages? (OpenAI wire format), used only on the API+tools path.
- adapter-cli: API branch prefers messages -> apiDispatchToolsHistory (prepends the project-context system prompt), else the Phase-1 single-prompt path.
- cli brain: renderAgentMessages reconstructs the bounded thread (last AGENT_MSG_KEEP_FULL=4 tool results verbatim, older trimmed to a short head — this is what keeps a long browse from bloating to the step backstop); synthetic contiguous call_<i> ids; safe-stringify so a circular tool input can't crash reconstruction. The brain builds it only when tools are in play (CLI engines keep the flat prompt).

Verified on the real wire: all three coding-plan endpoints (zai/kimi/minimax) accept the reconstructed thread (synthetic ids, contiguous pairs) and CONTINUE it correctly — each read the prior readPage tool-result and called click #submit next. +7 unit tests (56 brain-suite, 205 across dispatch/adapter/serve). 6-engine agon review pass; needs-check findings fixed. Images/API-vision remain a separate pre-existing gap (out of scope).

⚔️ Forged by [Agon](https://github.com/KERNlang/agon)

Co-Authored-By: agon (KERN) <292465531+KERN-Agon@users.noreply.github.com>
… + browser)

Dropped images had one root cause: the coding-plan engines were never declared vision-capable, so agon's vision gate (engine.capabilities?.includes('vision')) silently dropped every image — in CLI chat AND when driving the browser. Live-tested the three coding endpoints with a real image: kimi and minimax see perfectly (4/4 colors on a quadrant test), zai does not (it accepts the request but ignores the image).

- engines: declare capabilities:['vision'] on the minimax-coding-plan builtin default (kimi/minimax user-tier runtime defs updated locally too). NOT zai — its endpoint is blind, so the gate keeps (correctly) warning. Declaring vision instantly fixes CLI chat images for kimi/minimax (session-resume already sends image parts once vision is declared).
- core: attachVisionToMessages — splices encoded screenshot ImageParts into the native thread's last user turn for the API+tools path (browser brain), gated on the engine's vision capability. Preserves existing array parts (no data loss), omits an empty text part (some providers reject it), reuses encodeImagesForDispatch.
- adapter-cli: dispatch's API+tools branch attaches vision to the thread (synthesising a one-turn thread if a caller sends images without one, so images are never silently dropped); CLI/companion paths untouched. dispatchStream documented as prompt-only (no caller streams tools/vision).
- cli: composer pending-image chip now reads '[Image #N] filename' (Claude-style) + the one-row width budget updated.

Verified: kimi/minimax return correct descriptions of a sent image; non-vision engines remain byte-identical. +9 image tests (attachVisionToMessages: no-op gates, last-user splice, empty-text omission, array-part preservation). Full suite 3508 green (only 2 known-flaky). Two 6-engine agon reviews; all blocking/important findings fixed incl. a KERN ?? -ternary codegen bug and an Ink-TUI console.warn corruption. Out of scope (pre-existing): zai vision, streamed vision.

⚔️ Forged by [Agon](https://github.com/KERNlang/agon)

Co-Authored-By: agon (KERN) <292465531+KERN-Agon@users.noreply.github.com>
@cukas cukas merged commit 2e15e14 into main Jun 24, 2026
2 checks passed
@cukas cukas deleted the feat/agon-everywhere branch June 24, 2026 20:42
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