Repository navigation
feat(agents): enforce tool design rules in the shared agent harness - #22988
Conversation
Four rules move from the notes agent's local fixes (#22853) into the harness so Dream, chat and future agents get them from shared code: 1. Time windows default to context. A run carries a ContextWindow on its Mount (and Dream's Session): the conversation for notes, the trailing day for Dream, the attached chat timeframe or last 24 hours for chat. Time-range tools fill missing bounds with ContextWindow.resolve. Dream temporal search defaults to the day and reports the window it used; chat get_screen_activity_tool no longer requires start/end. 2. Times in UTC. model_json/model_view render every instant shown to the model with a trailing Z (notes tool results and packet, Dream seed and tool results). parse_tool_time converts offsets, reads naive times as UTC (chat: the user's zone, matching its labelled local display) and rejects nonsense with an error that names the field and the expected format. Dream search accepts offsets and naive times instead of rejecting them; chat screen search no longer silently drops an unreadable date. 3. Normalize before validating. Schemas declare near-miss keys as output_aliases data (ExtractedSection: body -> body_markdown); normalize_output/validate_output apply them recursively. Replaces the notes agent's ad-hoc normalize_submission; Dream tool arguments and the Dream verifier's structured output go through the same path. 4. Send-back budgets per failure class. SendBackBudget keeps one budget per class (notes: format, content, evidence). Format problems go back alone, so a format complaint can no longer spend the naming-evidence retry. Documents the rules in backend/utils/llm/ARCHITECTURE.md; tests in tests/unit/test_agent_tool_rules.py. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9e284d9db3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| start_dt, end_dt = _chat_context_window(config, clock).resolve( | ||
| start_date, end_date, naive_tz=clock.tz, start_field='start_date', end_field='end_date' | ||
| ) |
There was a problem hiding this comment.
Intersect explicit dates with the active chat scope
When the chat has an attached timeframe and the model supplies either date, ContextWindow.resolve lets the explicit bound win instead of intersecting it with the server-authored scope. In particular, now that either argument may be omitted, a start after the scoped end produces an entirely out-of-scope window of the same duration and queries the owner's screen history there. The chat contract is fail-closed, and utils/retrieval/chat_scope.py::apply_chat_scope_dates already rejects an empty intersection, so apply that scope before resolving/defaulting the summary range.
Useful? React with 👍 / 👎.
Summary
The agentic meeting-notes agent (#22853) failed to name meeting participants for two reasons. #22853 fixed both inside the notes agent only:
get_screen_activityrequired explicit start/end times. The model sent UTC clock times with a-07:00offset, so the tool searched the wrong hours.bodyinstead ofbody_markdown. Validation saw empty sections and spent its only send-back on a bogus "0 words / write bullets" complaint. That left no retry for the real problem: nobody was named.This PR moves those fixes into the shared agent harness (
utils/llm/shaped_agent.py+utils/model_text.py), so the notes agent, Dream, chat and future agents get them from shared code.Tool design rules (now enforced in code; documented in
backend/utils/llm/ARCHITECTURE.md)ContextWindowon itsMount(and on Dream'sSession). Time-range tools fill any missing bound withContextWindow.resolve.model_json/model_viewrender every instant shown to the model ending inZ.parse_tool_timereads time arguments: offsets are converted, andZor naive times are read as UTC. An unreadable time is a tool error that names the field and the expected format, never a silently wrong window.output_aliases: ClassVar[...](for example,ExtractedSectionmapsbodytobody_markdown).normalize_output/validate_outputapply these aliases recursively before validation.SendBackBudgetkeeps one budget per class (notes: format, content, evidence). Format problems are sent back alone, so a format complaint can no longer use up the evidence retry. Once a class's budget is spent, the output is repaired and accepted.What each agent gained
ContextWindow(the conversation, capped at 12 h) instead of_window/_as_utc,normalize_outputplus declared aliases instead ofnormalize_submission/_BODY_ALIASES,utc_z/model_jsoninstead of_utc_z/json.dumps(default=str), andSendBackBudgetinstead of a single shared rejection. An unreadable time is now a clear tool error. Before, it silently fell back to the conversation window.Sessioncarries a trailing-dayContextWindow. Temporal search defaults to it, reports thetime_windowit used, and the seed shows the window. Lexical and semantic bounds stay optional filters over all history.Searchnow accepts offsets and naive times (before, it rejected naive times). Seed and tool results showZtimes. Tool arguments and the verifier's structured output go throughnormalize_output/validate_output.CORE_TOOLS)get_screen_activity_toolno longer requires start/end. It defaults to the attached chat timeframe, or to the last 24 hours.search_screen_activity_toolused to drop an unreadable date silently and search unfiltered; it now returns a clear error. Both parse times with the harness parser.Chat deviation (deliberate): chat keeps its labelled local-time display (
format_instant, see #4643/#6214). So chat tools read a naive time in the user's zone, which is the zone the model was shown, instead of as UTC. Chat's other time tools already had optional dates where "no dates" means all history; they are unchanged.Behaviour changes to note
Search.start/enddescriptions changed, so the Dream tool bytes change once.Test plan
backend/tests/unit/test_agent_tool_rules.pycovers each rule:-07:00case, and the error messages;Zview;ContextWindowdefaults for notes, Dream and chat;test_screen_activity_tools_sanitization.pycovers the chat screen-tool defaults, offset and naive handling, and search date errors.test_notes_agent.py, where a bad submission now gets one send-back per class.BACKEND_UNIT_TEST_FILE_LIST=<175 test files importing the changed modules> nice taskpolicy -b bash backend/test.shexited 0, with every file process green.bash backend/scripts/typecheck.sh: 0 errors.scripts/pr-preflight --pr-body-file: passed (32 checks). The pre-push hook passed, including the backend unit gate.models/agent_tools.py.Live behaviour is not exercised: nothing is deployed. Prod backend deploys go through the rollout session.
🤖 Generated with Claude Code