Skip to content

feat(agents): enforce tool design rules in the shared agent harness - #22988

Merged
Git-on-my-level merged 1 commit into
mainfrom
lane/harness-tool-rules
Oct 21, 2026
Merged

Git-on-my-level merged 1 commit into
mainfrom
lane/harness-tool-rules

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Summary

The agentic meeting-notes agent (#22853) failed to name meeting participants for two reasons. #22853 fixed both inside the notes agent only:

  1. get_screen_activity required explicit start/end times. The model sent UTC clock times with a -07:00 offset, so the tool searched the wrong hours.
  2. The model put section bodies under body instead of body_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)

  1. Time windows default to the run's context. A run carries a ContextWindow on its Mount (and on Dream's Session). Time-range tools fill any missing bound with ContextWindow.resolve.
  2. Times in UTC. model_json / model_view render every instant shown to the model ending in Z. parse_tool_time reads time arguments: offsets are converted, and Z or 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.
  3. Normalize before validating. A schema declares near-miss keys as data: output_aliases: ClassVar[...] (for example, ExtractedSection maps body to body_markdown). normalize_output / validate_output apply these aliases recursively before validation.
  4. Send-back budgets per failure class. SendBackBudget keeps 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

Agent Gained
Notes agent Its local copies are replaced by the harness versions: ContextWindow (the conversation, capped at 12 h) instead of _window/_as_utc, normalize_output plus declared aliases instead of normalize_submission/_BODY_ALIASES, utc_z/model_json instead of _utc_z/json.dumps(default=str), and SendBackBudget instead of a single shared rejection. An unreadable time is now a clear tool error. Before, it silently fell back to the conversation window.
Dream The Session carries a trailing-day ContextWindow. Temporal search defaults to it, reports the time_window it used, and the seed shows the window. Lexical and semantic bounds stay optional filters over all history. Search now accepts offsets and naive times (before, it rejected naive times). Seed and tool results show Z times. Tool arguments and the verifier's structured output go through normalize_output/validate_output.
Chat (CORE_TOOLS) get_screen_activity_tool no longer requires start/end. It defaults to the attached chat timeframe, or to the last 24 hours. search_screen_activity_tool used 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

  • Notes: before, a submission got one send-back across all classes. Now, if it is still bad after its format send-back, it gets a content send-back as well (for example "too short"), as long as the turn and deadline budget allows. The existing test is updated to match.
  • Dream: the Search.start/end descriptions changed, so the Dream tool bytes change once.

Test plan

  • New backend/tests/unit/test_agent_tool_rules.py covers each rule:
    • lenient time parsing, including the -07:00 case, and the error messages;
    • the Z view;
    • ContextWindow defaults for notes, Dream and chat;
    • recursive aliases, strict JSON validation and Dream argument aliases;
    • per-class send-back budgets, plus a replay of the feat(notes): agentic meeting notes for long meetings #22853 incident in which the format send-back no longer uses up the naming send-back.
  • test_screen_activity_tools_sanitization.py covers the chat screen-tool defaults, offset and naive handling, and search date errors.
  • Updated: test_notes_agent.py, where a bad submission now gets one send-back per class.
  • Local pytest: 70 harness, notes, Dream, chat-scope, screen and model_text files, 1399 passed.
  • BACKEND_UNIT_TEST_FILE_LIST=<175 test files importing the changed modules> nice taskpolicy -b bash backend/test.sh exited 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.
  • CI runs the full backend unit suite, because the selector requires it for models/agent_tools.py.

Live behaviour is not exercised: nothing is deployed. Prod backend deploys go through the rollout session.

🤖 Generated with Claude Code

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]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T06:23:22.076571Z 9e284d9 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +452 to +454
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'
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

@Git-on-my-level
Git-on-my-level merged commit d75f584 into main Oct 21, 2026
68 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/harness-tool-rules branch October 21, 2026 06:37
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.

1 participant