anthropics / anthropics/financial-services

Critical Bug: Broken cross-agent handoffs due to truncated JSON extraction in orchestrate.py

Open
#99 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
34.8k
Forks
5.2k
Avg merge
2h 2m
Merged PRs (30d)
3

Description

A critical logic error was identified in the agent orchestration flow. The system fails to reliably route handoff requests between agents because the regular expression used to extract the `handoff_request `is too restrictive and fails on nested JSON structures.
## Technical Analysis
In `scripts/orchestrate.py` (lines 40-42), the regex is designed to capture the handoff payload. However, it is currently configured to stop capturing at the first closing brace (}).

Since a valid `handoff_request` contains a nested payload object, the regex terminates prematurely, leaving the JSON string malformed (missing the final outer closing brace). Consequently:

1. `json.loads()` at lines 49-52 fails.
2. The function returns None.
3. The handoff flow documented in ` managed-agent-cookbooks/*/README.md ` becomes non-functional.

## Example of the Failure
```
{
"handoff_request": {
"target_agent": "reader",
"payload": { "query": "fetch_logs" }
}
}
```
# Current Regex Behavior:
The regex stops at the first } (the one ending the nested payload).

- Captured String: `{"handoff_request": {"target_agent": "reader", "payload": {"query": "fetch_logs"}`
- Error: The final } is missing. `json.loads()` throws a `JSONDecodeError.`

## Proposed Fix

- Short term: Update the regex in scripts/orchestrate.py to be "greedy" or account for nested braces.
- Long term: Avoid using Regex to parse JSON. It is safer to use a proper JSON parser or a state-machine approach to find the start and end of the JSON block to ensure structural integrity.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.