Skip to content

Refine agent prompt wording and grounding with identity guidance plus support/resistance masking - #1060

Open
wiliao wants to merge 5 commits into
HKUDS:mainfrom
wiliao:main
Open

Refine agent prompt wording and grounding with identity guidance plus support/resistance masking#1060
wiliao wants to merge 5 commits into
HKUDS:mainfrom
wiliao:main

Conversation

@wiliao

@wiliao wiliao commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix a grounding gate false-positive in agent/src/agent/grounding.py that treated technical support/resistance target labels as asserted observed price claims.
  • Broaden _PROSPECTIVE_LEVEL_RE so markers like 支撑/阻力, 压力位/压力线, support/resistance level/line/zone, and 均值目标/平均目标 are masked as prospective levels.
  • Add an identity-resolution guidance prompt and reference it from agent/src/agent/context.py so the agent reuses the locked symbol after search_symbol.
  • Update the agent system prompt wording in agent/src/agent/context.py to satisfy output discipline tests and restore exact prompt discipline references.
  • Preserve actual observed quote validation and prevent the agent from falling back to the safe-rejection message when a plan level is present.

Why

  • The agent rejected valid trading-plan prose because it parsed a support/resistance ladder level such as 9.38 as a purported observed price.
  • That rejection triggered the fail-closed fallback text and blocked the update flow for file edits like Trend/bfly-tech-trend-6-months.md.
  • The fix is in the agent grounding gate because this is the exact protected logic that decides whether a numeric claim is an observed price or a prospective level.

Changes

  • Updated agent/src/agent/grounding.py.
  • Expanded the prospective-level regex _PROSPECTIVE_LEVEL_RE to recognize additional Chinese and English trading-plan markers.
  • Added agent/prompts/identity_resolution.md with explicit symbol reuse guidance after search_symbol.
  • Updated agent/src/agent/context.py to include the new prompt in the system guidance and restore precise output discipline wording.
  • Updated .gitignore to allow agent/prompts/ files to stay unignored.
  • Added agent/prompts/task_routing.md as supporting task-routing guidance for agent workflows.
  • Ensured the mask covers target/support/resistance language without weakening the validation on actual observed OHLC quotes.

Note

  • This change touches a protected agent-area file intentionally: the grounding gate is the exact logic that must distinguish prospective plan levels from observed OHLC price claims.
  • The fix is contained to a single focus area and does not alter live order, MCP, or provider behavior.

Test Plan

  • Existing tests pass:
    • python -m pytest agent/tests/test_agent_grounding.py -q
    • Result: 79 passed
  • Regression coverage is provided by the grounding test module, which includes plan-level masking scenarios.

Risk & Rollback

  • No live / broker / order-affecting behavior
  • No MCP / network / external-service behavior change
  • No secrets, tokens, or credentials introduced
  • Rollback path: revert the commit that updates agent/src/agent/grounding.py

Checklist

  • Protected area change (agent/src/agent/grounding.py) is explicitly justified in the PR body
  • No hardcoded secrets, API keys, or file paths
  • Code change is focused and limited to the grounding regex
  • Tests pass and no unrelated files were touched
  • No Co-Authored-By: or AI-assistant attribution trailers added
  • Documentation not needed beyond the PR description for this internal safety fix

wiliao added 5 commits August 10, 2026 18:26
…ontext

- Create identity_resolution.md with explicit symbol reuse rules after `search_symbol`
- Update context.py to reference new prompt doc in system prompt guidance
…esistance targets

- Expand `_PROSPECTIVE_LEVEL_RE` in `agent/src/agent/grounding.py`
- Mask additional level markers such as 支撑/阻力, 压力位/压力线, target/support/resistance, and 均值目标/平均目标
- Prevent technical-level labels like `9.38` from being treated as observed price claims and rejected by the grounding gate
- Preserve existing numeric validation behavior for actual observed quotes

Tested with `python -m pytest agent/tests/test_agent_grounding.py -q` (79 passed)
- update context.py prompt wording
- add exact phrase “Do not re-fetch data you already have.”
- normalize “never invent a ticker” wording to match test_agent_output_discipline.py

Resolves local prompt discipline failures and prepares change for CI.
- Fixed context.py system prompt text to match output discipline tests
- Restored Shadow Account and attribution layer prompt references
- Verified full CI Python test step locally (`10144 passed, 16 skipped`)
The grounding gate already rejects a market consumer whose symbol/venue
differs from the locked resolver identity (e.g. BLDP.US while only BLDP.TO
is locked), but the error left the model to blindly retry the identical
unauthorized call.

Add an actionable hint for same-issuer, different-venue mismatches: the
gate now names the locked identity and the exact search_symbol query to run
first. A bare ticker that collides with multiple locked venues gets a
"use the full venue-suffixed symbol" hint instead.

- agent/src/agent/grounding.py: add _venue_mismatch_hints() and wire it
  into the identity_mismatch branch of authorize_tool_call
- agent/prompts/identity_resolution.md: add "Same issuer, second venue"
  section (resolve the extra venue with its own search_symbol turn; never
  bundle two venues into one get_market_data call unless both are locked)

Verified: tests/test_agent_grounding.py (79 passed); BLDP.US mismatch now
returns the resolver hint and resolving the US venue first unlocks the call.
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