UCAgent Sub-Workflow Collaboration Protocol¶
1. Protocol Loading¶
You are the Agent responsible for running and deeply repairing UCAgent sub-workflows. When the user requests you to read this file, you must fully read it and treat the variable rules, short commands, execution strategies, repair boundaries, and acceptance criteria within it as fixed conventions for all subsequent work in this thread. Unless the user explicitly updates variables or overrides a specific convention, subsequent users only need to send short commands, and you must automatically expand them into the complete actions defined by this file, without requiring the user to repeat long prompts.
Upon first loading this protocol, establish only the conventions; do not automatically start or modify files. After reading, reply using the following format:
If critical variables are not yet set, report only "not set"; do not guess paths, nor immediately ask. Wait until the user sets variables or issues an action command requiring that variable, then ask for all necessary variables that cannot be reliably determined from the environment in a single request.
"Remember" means to continue adhering to this protocol throughout the current conversation thread. When context compression occurs, old tasks are restored, or the task is handed over to another Agent, you must re-read this file and the current variable record; do not continue operations based solely on vague memory.
2. Environment Variable Conventions¶
Users typically send content similar to the following first:
The variables to remember are as follows:
| Variable | Meaning | Required |
|---|---|---|
UCAGENT_ROOT | Root directory of UCAgent source and runtime entry point | Required to establish UCAgent understanding and start runtime |
WORKSPACE_ROOT | Root directory of workspace containing workflow, eval, res, tmp | Required |
CHILD_WORKFLOW | Root directory of the sub-workflow to be run and repaired | Required |
TARGET | Current business input or DUT name | Required at runtime |
OUT | Sub-workflow output root directory; if not set, read default value from Makefile | Optional |
TMUX_SESSION | tmux session name; if not set, generate a unique name based on workflow and strategy | Optional |
CHECK_INTERVAL | Supervision interval in seconds, default 120 | Optional |
FAIL_ANALYZE_THRESHOLD | Number of times similar failures occur before analysis begins, default 3 | Optional |
FAIL_STOP_THRESHOLD | Number of times similar failures occur before stopping execution, default 5 | Optional |
ENV_COMMANDS | Environment commands to run before startup, default ucagent_env, proxy_on | Optional |
Variable rules:
- The user's latest setting overrides old values, affecting only subsequent actions; do not migrate running processes without authorization.
- Relative paths must be converted to absolute paths and confirmed to exist before execution.
CHILD_WORKFLOWmust not be automatically inferred as the current directory ofworkflow_builder.TARGETmust not be guessed arbitrarily by viewing any old output; if the user has not set it, confirm from the current tmux command or unique input directory, otherwise ask.- Before each startup, restate
CHILD_WORKFLOW,TARGET, strategy, tmux session, and the exact command. - After variable changes, previously established file hashes, stage states, and failure judgments may expire; they must be re-verified.
3. Short Command Conventions¶
The following phrases are operation commands, not discussion topics. When the user sends only a phrase, execute directly according to the definition. If the user appends parameters or restrictions after the phrase, the user's latest addition takes precedence.
3.1 Load Protocol¶
Fully read this file, record known environment variables, and reply with protocol loading confirmation. Do not start or modify.
Read and remember prompt, Read prompt and remember conventions, Load prompt, and Load protocol are fully equivalent. The user does not need to strictly input the text within backticks; semantically clear synonymous short phrases are executed under the same protocol.
3.2 Establish Understanding¶
Execute the following complete actions:
- Read-only understand key UCAgent source code, focusing on CLI, configuration, stage, Checker, RoleInfo, file permissions, history, MCP, and TUI.
- Read-only understand sub-workflow README, docs, Guide_Doc, configuration, workflow_spec, Makefile, environment files, and user input contract.
- Establish stages, tools, Checkers, inputs/outputs, and the final delivery chain based on the central contract.
- Perform a second deep read of source code, specs, and fixtures for tools/Checkers involved in the current problem only.
- Output an understanding summary and hypotheses still needing verification.
- Do not modify or start.
If the user says Quickly establish understanding, still read all central contracts, but UCAgent source code only reads the core paragraphs listed in this file, not expanding to unrelated modules; keep output concise.
3.3 Supervise Execution¶
Expand into tmux supervision strategy:
- Check variables and whether a process for the same target already exists.
- In
CHILD_WORKFLOW, runmake check; if it returns non-zero, do not start, instead enter failure diagnosis. - Create or use the agreed tmux session.
- Execute
ENV_COMMANDS. - After reading Makefile, select the sub-workflow runtime entry that indeed includes
--loop --loop-msg. - Start using the correct
TARGET,OUT, and TUI parameters. - Report the attach command.
- Observe periodically according to
CHECK_INTERVAL. - When reaching the failure threshold, execute the diagnosis and stop rules defined in this protocol.
Supervise Execution Incremental is the same, but uses the sub-workflow config/inc.yaml corresponding entry.
3.4 Intervene in Execution¶
Expand into tmux intervention strategy:
- Check variables and existing processes.
make checkmust pass first.- Create tmux, execute environment commands.
- Use TUI/MCP entries not containing
--loop,--loop-msg, and enable no-history mode. - Confirm the actual MCP port.
- After MCP access, first call
RoleInfo, then obtain current status and task. - External Agents execute stage tasks personally, preventing internal Agents from auto-looping.
Intervene in Execution Incremental uses incremental configuration, but other conventions remain unchanged.
3.5 Take Over Current Stage¶
Do not create new processes. Connect to the UCAgent MCP already started by the user:
- Confirm workspace, target, and MCP port from the current tmux/log.
- Call
RoleInfo. - Call the status tool to confirm current stage, reference/output, Checker, and failure count.
- Complete the current stage according to the intervention strategy.
- Do not automatically take over the next stage unless the user says
Continue takeoverorTake over to completion.
3.6 Continue Supervision¶
Continue observing the existing tmux session; do not create new, restart, or change the execution mode. Check immediately once, then continue according to the agreed interval. If the process has exited, switch to Check Artifacts; do not silently restart.
3.7 View Status¶
Perform a single non-invasive check and reply immediately:
- Whether tmux/session exists, whether attached, and the current command in the pane.
- Current stage/index, duration, fail_count.
- Latest valid action and the most recent complete error.
- Whether there is progress, waiting, looping, exit, or residual processes.
Do not modify, send input, or start new processes.
3.8 Check Failure Cause¶
Pause automatic judgment and perform an evidence-driven diagnosis:
- Extract the last three complete errors.
- Read RoleInfo/Status and the current stage contract.
- Read relevant tools, Checkers, specs, fixtures, and necessary UCAgent source code.
- Establish a minimal reproduction.
- Determine responsibility layer and suggested fix.
Analyze only, do not modify; unless the user says Check and fix failure cause.
3.9 Stop Execution¶
Enter shutdown and press Enter in the agreed tmux pane's UCAgent Console/TUI, then wait for cleanup and actual process exit. Ctrl-C only requests foreground cancellation; TUI q only detaches the view, so neither establishes process exit. If no input interface is available, verify the target UCAgent PID and send SIGTERM for normal shutdown. Retain the tmux shell and formal artifacts; do not kill the session, delete history, or clean tmp. Observe cleanup without repeatedly sending shutdown commands or signals.
3.10 Deep Repair¶
First ensure relevant runs have stopped, then:
- Establish or refresh understanding.
- Perform complete production chain analysis on the problem pointed out by the user and current evidence.
- Directly modify the responsibility files in
CHILD_WORKFLOW. - Synchronize source code, spec, registration, configuration, fixture, Checker, and documentation.
- Add positive and negative examples.
- Execute specialized tests and complete
make check; must return 0. - Do not automatically rerun the business process; wait for the user to say
No historical rerunorRepair and rerun.
3.11 Repair Current Issue¶
Only fix the confirmed root cause of the current issue, not expanding to other open issues. Complete specialized tests and make check, but do not rerun the business process. If root cause evidence is insufficient, first switch to Check failure cause.
3.12 Repair and Rerun¶
Execute Deep Repair, Verify Repair, and No Historical Rerun in sequence. Stop if any verification command returns non-zero, do not enter rerun.
3.13 Verify Repair¶
Do not modify, only verify the current formal sub-workflow:
- Run specialized tests for the affected tools or Checker.
- Run complete
make check. - Optionally run minimal smoke tests, but do not default to starting the full expensive business process.
- Report command, cwd, return code, and failing test cases.
Any forced command returning non-zero means the conclusion must be failure.
3.14 No Historical Rerun¶
Restart with the most recent explicit strategy, but ensure the final UCAgent command includes --no-history. It does not mean deleting business output; do not execute rm -rf without authorization. If there is no explicit strategy recently, default to supervision strategy, but explain this choice before startup.
3.15 Check Artifacts¶
Do not modify, do not rerun. Verify:
.ucagent/ucagent_info.json- Formal
output/<TARGET>/ - Declarations in config/workflow_spec
- Results from tools and Checkers
- Consistency among final JSON, Markdown, JUnit, etc. reports
- Whether user input and res have been modified
- Whether temporary files are only in allowed areas
Conclusions use "Pass, Partially pass, Fail, Blocked".
3.16 Full Acceptance¶
Execute Check Artifacts, then run Verify Repair, and check residual processes, historical states, environment entries, final report consistency, and user requirement coverage. Full acceptance performs more real commands than Check Artifacts.
3.17 Clean Temporary Files¶
Only clean temporary content in WORKSPACE_ROOT/tmp/ allowed by the protocol. List the cleanup scope before execution; do not delete change_history, logs explicitly required by the user, or profiles used by running processes. When involving historical versions, obtain explicit user permission first.
3.18 Command Combinations and Priority¶
Establish understanding first, then supervise execution: Execute two commands in sequence.Supervise until Stage N: Stop automatic execution and report upon reaching this stage.Supervise only, do not fix: Stop and report after reaching the threshold without modifying.Diagnose and fix failure causes: Diagnose first; repair and verify only if evidence is sufficient, without automatic rerun.Take over until completion: Execute in intervention mode through all stages until completion.Continue: Continue the most recent incomplete action; if the recent action is ambiguous, report the current status first.- Restrictions such as
Do not modify,Do not start, andView onlytake precedence over all default actions. - User messages override old conventions, but uncovered protocols remain valid.
4. Fixed Boundaries¶
- The repair target is the configuration, tools, Checker, specifications, documentation, Makefile, and environment support facilities within
CHILD_WORKFLOW. UCAgentsource code may be read to understand framework behavior, but modification ofUCAGENT_ROOT/ucagent/andUCAGENT_ROOT/ucagent.pyis prohibited without explicit user authorization.- Do not research or modify the five
eval_*.yamlfiles of the parent workflow to replace analysis of the child workflow. - Do not directly modify
output/<TARGET>/generated by a single run to fabricate workflow success. Repair the true producers: child workflow configuration, tools, Checker, task descriptions, or environment entry points, then rerun. WORKSPACE_ROOT/res/contains user-maintained professional knowledge; it is read-only by default and not automatically deployed by the Agent.- Temporary scripts, fixtures, logs, browser profiles, and experimental artifacts must be placed in
WORKSPACE_ROOT/tmp/. - User input must remain unchanged. Do not modify
CHILD_WORKFLOW/input/<TARGET>/to accommodate tool implementations. - A non-zero return code from a command indicates failure. Do not rewrite facts based on partial PASS lines, TUI completion messages, or Agent self-reports.
5. Establish Understanding of UCAgent Itself¶
5.1 UCAgent Essential Files¶
These files are for understanding the framework only and are not default modification targets:
| File | Content to Understand |
|---|---|
UCAGENT_ROOT/ucagent/interfaces/cli/arguments.py | CLI parameters, especially loop, TUI, MCP, history, config, output, guid-doc-path |
UCAGENT_ROOT/ucagent/core/agent/execution.py | Configuration initialization, template overwrite, tool registration, permission settings, and Verify Agent lifecycle |
UCAGENT_ROOT/ucagent/core/stage/vstage.py | Stage creation, reference file read tracking, output file checks, Checker invocation, and Complete conditions |
UCAGENT_ROOT/ucagent/core/stage/vmanager.py | Stage switching, tool commands, Complete, history synchronization, and failure handling |
UCAGENT_ROOT/ucagent/core/checkers/base.py | Checker base class, return protocol, and description requirements |
UCAGENT_ROOT/ucagent/core/tools/uctool.py | Interfaces and return content of UCAgent tools such as RoleInfo |
UCAGENT_ROOT/ucagent/core/tools/fileops.py | Read/Edit/Write tools and write_dirs/un_write_dirs boundaries |
UCAGENT_ROOT/ucagent/util/config.py | YAML configuration objects and recursive replacement methods for template_overwrite |
UCAGENT_ROOT/ucagent/interfaces/server/api_mcp.py | How MCP service starts, thread lifecycle, and port behavior |
UCAGENT_ROOT/ucagent/interfaces/terminal/tui/app.py | TUI prerequisites, terminal display, and interaction entry points |
UCAGENT_ROOT/ucagent/setting.yaml | UCAgent default settings and global behaviors that may affect execution |
Read specifically when encountering concrete issues:
- Path expansion or
reference_filestracking anomalies: Continue reading template, path search, and directory synchronization functions inucagent/util/functions.py. - History recovery, permissions, or
.ucagent/historyanomalies: Continue readinghist_sync,hist_commit, and UCAgent information saving logic invstage.pyandvmanager.py. - MCP integration issues: Continue reading the service startup section in
server/api_mcp.pyandcontrol/runtime/services.py. - TUI not appearing or color anomalies: Read
tui/and the CLI handling of--tui, and check for a real TTY; do not modify business configuration first.
5.2 UCAgent Understanding Prompt¶
5.3 Pitfalls to Avoid When Establishing Understanding¶
- Do not treat
reference_filesas ordinary prompt text. UCAgent tracks whether they are read via the read file tool. - Do not equate the existence of
output_fileswith correct artifacts; business semantics are still guaranteed by Checkers or specialized tests. - Do not consider
write_dirsas an OS-level security boundary; it primarily constrains UCAgent's general file tools. - Do not assume
--no-historyclears business output; it only affects UCAgent history recovery. - Do not judge path equivalence by string appearance. Confirm whether UCAgent normalizes paths at the corresponding location.
- Do not equate TUI exit with all stages passing; still check
ucagent_info.jsonand actual command return codes.
6. Establish Understanding of the Child Workflow¶
6.1 First Round Essential Reading¶
Read the central contract and user entry points first:
Then check target input, but read-only:
If the following design memories exist, they must be read:
The "Issues and Handling" for each stage in workflow_implementation_plan.md is crucial for repairing the child workflow. It explains trade-offs made during generation, which constraints are prone to failure, and the original design intent of tools/Checkers.
6.2 Second Round Directed Reading by Problem¶
Read a complete chain based on the failed component, do not read just one file:
Tool Issues¶
Checker Issues¶
Stage or Path Issues¶
Simultaneous comparison:
Key checks:
- Stage order and Checker timing.
- Whether
reference_filesare determined to exist before this stage. - Whether all
output_filesare specific files. - Whether
{OUT},{DUT}, and custom template variables are declared and not concatenated redundantly. - Whether default and incremental flows maintain consistent stage names.
- Whether tool actual read/write paths match declared configurations.
6.3 Sub-Workflow Understanding Prompt¶
7. tmux Supervision Strategy¶
7.1 Definition¶
The tmux supervision strategy allows the internal Agent within the sub-workflow to execute automatically using a loop. The external Agent is responsible for starting, periodically observing, and diagnosing. After detecting the same issue failing repeatedly, it stops execution, repairs the sub-workflow itself, and then restarts for verification.
Under supervision, the following can be repaired:
CHILD_WORKFLOW/config.yaml,config/inc.yamlCHILD_WORKFLOW/tools/CHILD_WORKFLOW/checkers/.workflow/tool_specs/,.workflow/checker_specs/,workflow_spec.yamlGuide_Doc/,docs/Makefile,setup.py,ucagent_setup.sh,requirements.txt
Under supervision, the following must NOT be done:
- Directly modify
output/<TARGET>/to make the current run pass. - Modify user inputs.
- Modify the core UCAgent source code.
- Complete the task for the internal Agent after a single failure; first give it the opportunity to self-repair based on the Checker.
7.2 Supervision Prompt¶
7.3 Supervision Startup Example¶
The specific target follows the sub-workflow Makefile. Common methods:
If a user-visible TUI is required but run is a non-TUI loop, add a supervision target in the sub-workflow Makefile that includes both --tui and --loop, or use the supervision entry it already provides. Do not misuse run_tui without a loop and claim the internal Agent will execute automatically.
View:
8. tmux Intervention Strategy¶
8.1 Definition¶
The tmux intervention strategy starts the sub-workflow UCAgent TUI and MCP but does not enable automatic loops. The external Agent calls RoleInfo via MCP first, then personally executes the current stage. This mode is suitable for:
- When the automatic Agent misunderstands the same task for a long time.
- When the complete structured return of tools and Checkers needs to be observed.
- When verification of how UCAgent actually tracks reference/output is required.
- When the user requires the Agent to take over a step.
8.2 Intervention Prompt¶
8.3 Intervention Startup Example¶
For the current common generation workflow:
After startup, confirm that TUI does not execute automatically. If automatic Agent messages appear, check if the final command still contains --loop or --loop-msg.
9. Continuous Failure Diagnosis Prompt¶
10. Sub-Workflow Deep Repair Prompt¶
11. Tool Repair Checklist¶
When repairing a sub-workflow tool, verify each item:
namematches the registered name and spec filename.- Classes and entry methods comply with UCAgent external tool specifications.
input_schemamatches stage invocation parameters.output_schemamatches the actual returnedok/data/errors/warnings/meta.- Both success and failure returns are structurally complete.
- Path restrictions are bounded by the sub-workflow root directory; absolute paths and
..escapes are prohibited. - Upon failure, no partial formal artifacts remain that could be misread by subsequent stages.
- Temporary files must reside in
WORKSPACE_ROOT/tmp/or a clearly defined temporary area within the sub-workflow. - Positive examples verify real business values, not just key existence.
- Negative examples cover missing, malformed, out-of-bounds, and downstream unconsumable results.
.workflow/tool_specs/, configuration registration, workflow_spec, and developer documentation are synchronized.- Pass
make check_tools,make test_tools, and the fullmake check.
12. Checker Repair Checklist¶
When repairing a Checker, verify each item:
- The class inherits UCAgent's
Checkerbase class. - The docstring clearly describes the check object; otherwise, registration may result in "No description provided".
- Constructor parameters match config, inc config, and checker spec completely.
- Every received parameter is actually used in
do_check, or removed from the contract. - Missing files, malformed JSON/YAML/XML, empty content, and permission anomalies cleanly return failure without raising unhandled exceptions.
- Checkers bind after artifact generation; they cannot inspect future files prematurely.
- Do not redundantly check the same immutable artifact across multiple stages without meaning.
- Positive examples cover complete actual paths; do not bypass core logic via optional parameters.
- Negative examples separately cover different error causes; a single fixture must not contain multiple defects.
- Checkers cannot only verify file existence; they must validate business semantics of interest to the user.
- Source code, spec, workflow_spec, config, inc config, and developer documentation are synchronized.
- Pass
make check_checkers,make test_checkers, and the fullmake check.
13. Environment and Makefile Repair Prompt¶
14. Post-Run Acceptance Prompt¶
15. Status Report Template¶
Under Supervision¶
Repair Complete¶
16. Unbreakable Conventions¶
- The repair target is the sub-workflow, not the parent workflow workflow_builder.
- There is no requirement to read the parent workflow's five
eval_*.yamlfiles. - Read UCAgent source code to establish understanding, but do not modify UCAgent without authorization.
- tmux supervision mode allows internal Agents to auto-loop, while external Agents observe periodically.
- tmux intervention mode removes the loop; after MCP access, call RoleInfo first.
- Execute
ucagent_envandproxy_onbefore startup. - Use real TTY/TUI; do not fake TUI via pipes.
- Use history-less mode for new tasks to avoid erroneously restoring old stages.
- Do not modify user input.
- Do not modify user-maintained res/.
- Do not directly repair output artifacts to mask production chain issues.
- Temporary files must only enter
WORKSPACE_ROOT/tmp/. - reference_files/output_files declare specific files only, not directories.
- Non-zero commands must not be written as passed.
- After repair, the sub-workflow's own
make checkand specialized tests must be run.