Add next-turn parameters and tool-call approval to the agent loop#23
Merged
Conversation
A tool may now return a next_turn block in its result to steer the following model turn (model, temperature, token budget, instructions). The sidecar feeds it to the Agent SDK's nextTurnParams; the in-process loop applies it directly. Both paths honour the same four parameters. Tool calls can be gated on human approval: list tool names in AGENT_APPROVAL_TOOLS or risk tiers in AGENT_APPROVAL_RISKS, or set requires_approval on a tool. A gated call posts an Approve / Reject prompt in the channel; a rejected call never runs and the model is told it was declined. Approval is resolved on the bot side, so the sidecar stays stateless per turn and the build guard still holds. Bumps the bridge protocol to v2 for the optional next_turn frame field.
Replace the vague "always use rg, fall back to grep if it fails" guidance with a deterministic rule: rg searches a directory or the whole workspace, grep searches a single named file. Updates the shell.run description, its command example, the allowlist comment and the README to match.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends the agent loop with two within-turn controls from the OpenRouter Agent SDK, implemented so the sidecar stays stateless per turn (the
test_sidecar_guards.pyguard still holds) and conversation state stays in the bot.next_turnblock in its result to steer the following model turn: a differentmodel, a newtemperature, a tightermax_output_tokens, or extrainstructions. The sidecar wires every bridged tool to the SDK'snextTurnParamsand forwards the directive on thetool_resultframe; the in-process loop applies the same directive directly. Both paths honour the identical four parameters.AGENT_APPROVAL_TOOLS, risk tiers inAGENT_APPROVAL_RISKS, orrequires_approvalon aToolSpec. With both config lists empty (the default) nothing is gated and behaviour is unchanged. Approval is resolved entirely on the bot side, and fails closed when no approver is reachable.The shared logic lives in the new
ai/agent_control.py, used by both the in-process loop and the sidecar bridge. The wire protocol is bumped to v2 for the optionalnext_turnfield; a version mismatch falls a turn back to the in-process loop as before, and that loop fully supports both features.Changes
ai/agent_control.py(new) --next_turndirective validation/application and the approval gate.agent-sidecar/src/server.ts-- wiresnextTurnParams, readsnext_turnofftool_result, protocol v2.ai/agent_sidecar.py,ai/tools.py-- approval gate plusnext_turnhandling on both agent paths;ToolSpec.requires_approval,ToolContext.approver.cogs/chat.py,cogs/chat_views.py-- the Discord Approve / Reject prompt and renderer status line.config.py,.env.example,README.md-- newAGENT_APPROVAL_*settings and docs.Test plan
python -m pytest tests/-- 157 passing, including the newtests/test_agent_control.pyand the unchanged sidecar statelessness guard.npm run buildinagent-sidecar/-- type-checks and builds clean.python -m compileall config.py main.py framework ai cogs.next_turndirective retunes the following turn.Generated by Claude Code