21 KiB
21 KiB
AgentScope Skill + CLI Tool Refactor Implementation Checklist
Purpose
This file is the execution checklist for implementing the PRD in:
.trellis/tasks/04-20-refactor-tool-cli-skill-ui-schema/prd.md
Use this document as the working guide during implementation. Do not mark an item complete until the code, docs, and verification for that item are actually done.
Required Standards Read Before Backend Changes
- Read
backend/AGENTS.md - Read
.trellis/spec/backend/index.md - Read
.trellis/spec/backend/database-guidelines.md - Read
.trellis/spec/backend/error-handling.md - Read
.trellis/spec/backend/logging-guidelines.md - Read
.trellis/spec/backend/quality-guidelines.md - Confirm
.trellis/spec/backend/type-safety.mddoes not exist; use current backend schema/type rules frombackend/AGENTS.mdand repository code as the effective type-safety baseline
Non-Negotiable Constraints
- Protocol docs are updated before implementation changes that alter contracts
- New backend runtime code reads configuration only through
core.config.settings - New backend runtime code uses project logging, never
print() - New backend errors follow RFC 7807 with stable
code - Any new or changed error codes are updated in
docs/protocols/common/http-error-codes.md - Repository/service layering remains intact
owner_idis never treated as a credential- No new error swallowing is introduced
ToolAgentOutput.resultremains the canonical machine-oriented tool result field
Execution Order
- Phase 0 completed before any runtime contract change is implemented
- Phase 1 completed before replacing tool execution with CLI-backed wrappers
- Phase 2 completed before auth credential transport is wired into queue/runtime
- Phase 3 completed before frontend contract alignment begins
- Phase 4 completed before cleanup is considered done
- Phase 5 verification completed before task is marked finished
Phase 0: Protocol Docs First
0.1 Define the tool protocol source of truth
- Add
docs/protocols/agent/tool-protocol.md - Document that CLI execution produces structured
resultas the source payload - Document that
ToolResponseonly carries the text projection ofresult - Document that runtime tool post-processing reconstructs full
ToolAgentOutput - Document that tool post-processing is responsible for
status,error, andui_hints - Document that
message.contentis the full JSON text projection ofToolAgentOutput.result - Document that
ToolAgentOutputis used for SSE, persistence, history recovery, and context rebuild - Document CLI input channel split:
argvprimary,stdinsecondary, environment variables for controlled auth injection - Document stdout JSON shape and non-zero exit semantics
- Document that shell execution is not exposed; router is whitelist-only
0.2 Remove ui_schema from active protocol
- Update
docs/protocols/ui/data-flow.md - Replace worker-driven UI source descriptions with tool-driven
ui_hints - Explicitly document that worker output no longer includes
ui_hints - Explicitly document that history tool UI recovery reads
metadata.tool_agent_output.ui_hintsand compiles toui_schema - Update
docs/protocols/ui/ui-schema.md - Clarify that
ui_hintsis the descriptive UI representation (source),ui_schemais the rendered format (wire format) - Clarify that frontend renderer continues to consume
ui_schema - Document that
ui_hints → ui_schemacompilation path remains unchanged, onlyui_hintssource changes
0.3 Update SSE and HTTP contracts
- Update
docs/protocols/agent/sse-events.md - Remove worker
ui_hintsfromTEXT_MESSAGE_END - Define
TOOL_CALL_RESULTpayload withui_schema(compiled fromui_hints) - Document that
ui_hints → ui_schemacompilation happens in backend codec - Provide examples where
resultis object-shaped instead of string-shaped - Update
docs/protocols/agent/api-endpoints.md - Define
/historyresponse contract for tool UI replay frommetadata.tool_agent_output.ui_hintscompiled toui_schema - Remove any statement that
/historyis assistant-only UI-wise if tool UI replay is now supported - Update
docs/protocols/agent/run-agent-input.md - Clarify that frontend does not submit auth token as tool arg
- Clarify that backend-controlled tool registration remains backend-owned
0.4 Update auth and automation protocol docs
- Update
docs/protocols/models/auth.md - Define controlled credential purpose, TTL, scope, and audit expectations
- Define relationship between normal bearer issuer and automation credential issuer
- Update
docs/protocols/models/automation-jobs.md - State that
owner_idis only an identity reference, not a credential - Document automation credential issuance path before queue/runtime execution
- Update
docs/protocols/common/http-error-codes.mdif new codes are introduced for CLI/runtime/credential failures
0.5 Phase 0 verification
- Confirm protocol docs no longer describe worker
ui_hintsas UI source - Confirm protocol docs explicitly document
ui_hints → ui_schemacompilation path - Confirm docs explicitly define ToolResponse vs ToolAgentOutput responsibility split
- Confirm docs explicitly define
/historytool UI replay path (fromui_hintscompiled toui_schema) - Confirm docs explicitly define controlled credential transport and TTL
Phase 1: Backend Contract Models And Persistence Path
1.1 Refactor runtime schemas
- Update
backend/src/schemas/agent/runtime_models.py - Remove
WorkerAgentOutputRich.ui_hints - Remove
AgentOutputinheritance that depends on worker UI payload - Make
resolve_worker_output_model()return the non-UI worker output model path - Change
ToolAgentOutput.resultfromstrto JSON-native structured payload type - Add
ui_hintstoToolAgentOutput - Keep
ToolAgentOutputstrict withextra="forbid" - Review any validator changes required to keep result deterministic and JSON-native
1.2 Update chat message metadata schema consumers
- Review
backend/src/schemas/domain/chat_message.py - Ensure
tool_agent_outputaccepts the updated structuredToolAgentOutput - Confirm metadata serialization remains compatible with persistence and context cache usage
1.3 Separate ToolResponse from ToolAgentOutput
- Update
backend/src/core/agentscope/tools/utils/tool_response_builder.py - Stop serializing full
ToolAgentOutputdirectly intoToolResponse.content - Make
build_tool_response()emit only the text projection ofresult - Decide and implement the helper that projects structured
resultto stable JSON text - Update error response builder to follow the same split cleanly
1.4 Add tool post-processing path
- Introduce a runtime tool post-processing module in backend tool/runtime layer
- Define the post-processor input contract from raw tool execution result
- Define the post-processor output as full
ToolAgentOutput - Ensure post-processor is the only place generating
ui_hintsfor tools - Ensure worker code does not generate tool UI fields anymore
1.5 Update parsing and stage emission
- Update
backend/src/core/agentscope/utils/parsing.py - Stop assuming text blocks contain full serialized
ToolAgentOutput - Add helpers to parse the text projection back into structured result where required
- Update
backend/src/core/agentscope/runtime/stage_emitter.py - Remove worker
ui_hintsemission from final text events - Emit
TOOL_CALL_RESULTbased on full post-processedToolAgentOutput - Ensure emitted tool payload carries structured
resultandui_hints
1.6 Update AG-UI codec and event storage
- Update
backend/src/core/agentscope/events/agui_codec.py - Remove worker
ui_hints -> ui_schemacompilation path - Remove
ui_schema-specific output shaping - Ensure tool events pass through tool-derived
ui_hints - Update
backend/src/core/agentscope/events/store.py - Persist tool message
contentas the JSON text projection ofresult - Persist full post-processed
ToolAgentOutputin metadata - Ensure worker metadata no longer expects
ui_hints
1.7 Unify cold/hot runtime paths
- Update
backend/src/core/agentscope/runtime/tasks.py - Replace
_serialize_tool_agent_output()assumptions that rely on oldToolAgentOutputshape - Ensure context rebuild uses the same content projection rule as hot-path execution
- Stop rebuilding tool context from legacy string-only result assumptions
- Review
backend/src/core/agentscope/caches/context_messages_cache.py - Define whether old cache payloads are backward-read compatible or intentionally invalidated
- Ensure runtime cold path and hot path see the same tool message shape
1.8 Update /history backend shaping
- Update
backend/src/v1/agent/utils.py - Remove worker
ui_hintscompilation logic - Stop returning
ui_schema - Add tool UI replay logic from
metadata.tool_agent_output.ui_hints - Keep user attachment handling intact
- Update
backend/src/v1/agent/schemas.py - Remove
UiSchemaRendererdependency fromHistoryMessage - Redefine history response shape to carry tool UI replay payload
- Update role constraints if tool-derived history items need explicit representation
- Review
backend/src/v1/agent/repository.pyfor any history query assumptions that prevent tool UI replay
1.9 Phase 1 verification
- Unit tests cover
ToolAgentOutput.resultas structured payload - Unit tests confirm worker output schema no longer includes
ui_hints - Unit tests confirm ToolResponse no longer embeds full ToolAgentOutput
- Unit tests confirm event store persists full ToolAgentOutput metadata and projected content separately
- Unit tests confirm
/historyshaping no longer emitsui_schema - Unit tests confirm tool UI replay uses
metadata.tool_agent_output.ui_hints
Phase 2: CLI-Backed Tools And Skill Registration
2.1 Replace direct Python tool registration
- Update
backend/src/core/agentscope/tools/tool_config.py - Replace function-name-centric mapping with CLI capability/wrapper-centric mapping
- Unify config and runtime skill selection on
enabled_skills - Keep approval config support aligned with the new tool names
- Update
backend/src/core/agentscope/tools/toolkit.py - Remove direct imports of
custom/calendar.py,custom/memory.py,custom/user_lookup.py - Register CLI-backed wrappers instead of Python business functions
- Preserve
enabled_skillsfiltering behavior
2.2 Add CLI adapter, router, and entrypoint
- Add a CLI adapter module in
backend/src/core/agentscope/tools/ - Adapter must invoke only the project CLI entrypoint
- Adapter must pass args via
argvprimarily andstdinsecondarily where required - Adapter must inject auth credential only via controlled environment variables
- Adapter must parse stdout JSON and map failures to structured errors
- Add a command router module in
backend/src/core/agentscope/tools/ - Router must be whitelist-only
- Router must map commands to Python handlers
- Router must not expose generic shell execution
- Add a Python console entrypoint module in
backend/src/core/agentscope/tools/ - Update
pyproject.tomlwith the console script entry
2.3 Migrate tool implementations to CLI handlers
- Replace old
backend/src/core/agentscope/tools/custom/*.pydirect runtime tools with CLI handler implementations - Remove old direct AgentScope tool-function implementations from final runtime wiring
- Ensure new handlers only call allowed internal services/repositories
- Ensure handler boundaries follow schema -> repository -> service layering
- Ensure handlers raise typed errors instead of transport exceptions where applicable
2.4 Register AgentScope skills
- Populate
backend/src/core/agentscope/tools/customwith skill assets using AgentScope-native layout - Add required
SKILL.mdfiles - Ensure skill content explains when to use each tool and how to compose them
- Register skills through AgentScope-native registration path in toolkit/runtime setup
- Ensure skill assets are included in runtime/deployment packaging
2.5 Update runner and middleware linkages
- Update
backend/src/core/agentscope/runtime/runner.py - Build toolkit from CLI-backed wrappers instead of Python functions
- Keep
enabled_skillsand stage-based selection behavior intact - Update
backend/src/core/agentscope/tools/tool_middleware.py - Ensure middleware name resolution still works with the new tool registration path
- Update
backend/src/core/agentscope/prompts/agent_prompt.py - Remove any prompt assumptions that still act as pseudo-skill behavior
- Keep prompt aligned with skill-driven disclosure instead of duplicating the full tool contract
2.6 Phase 2 verification
- Unit tests cover CLI adapter success path
- Unit tests cover CLI adapter malformed stdout path
- Unit tests cover CLI adapter non-zero exit path
- Unit tests confirm toolkit only registers enabled CLI-backed tools
- Unit tests confirm middleware still recognizes the active tool names
- Smoke test confirms AgentScope skill registration succeeds from project skill assets
Phase 3: Controlled Credential And Queue Transport
3.1 Define backend auth runtime objects
- Review
backend/src/core/auth/models.py - Add any missing auth runtime model needed for controlled credential transport
- Keep
CurrentUseras identity model if still appropriate, but do not overload it as credential carrier without an explicit design
3.2 Add controlled credential issuance path
- Add a credential issuer service under
backend/src/core/auth/or another appropriate auth module - Keep issuer in the same trust boundary as current bearer token issuing system
- Ensure issued credential is short-lived according to PRD target
- Ensure issuer encodes only the minimal scope required for tool execution
- Ensure logs do not expose raw credentials
3.3 Wire chat enqueue path
- Update
backend/src/v1/agent/service.py - Stop enqueueing only
owner_idfor runtime auth purposes - Enqueue the controlled credential or resolvable credential handle required by worker runtime
- Ensure queue payload does not expose raw token in model-visible fields
- Keep session ownership checks intact
3.4 Wire automation dispatch path
- Update
backend/src/core/automation/scheduler.py - Stop creating runtime auth solely as
CurrentUser(id=owner_id) - Issue or obtain automation controlled credential before enqueueing run
- Ensure
owner_idremains only a lookup/reference input - Ensure automation runtime uses the same CLI auth injection mechanism as chat runtime
3.5 Update task runtime injection
- Update
backend/src/core/agentscope/runtime/tasks.py - Read controlled credential from queued command payload
- Inject controlled credential into CLI runtime environment variables
- Remove any path that implicitly depends on
owner_idas execution credential - Keep user-context loading behavior explicit and separate from auth credential handling
3.6 Add settings and error mapping
- Update
backend/src/core/config/settings.pyfor any new CLI/credential configuration - Keep new config values typed and centralized
- Update error handling paths to use stable problem codes for credential/CLI failures
- Update docs/protocols/common/http-error-codes.md if these codes are new
3.7 Phase 3 verification
- Unit tests confirm chat enqueue includes required controlled credential transport data
- Unit tests confirm automation dispatch no longer relies on
owner_idas credential - Unit tests confirm task runtime injects controlled credential only via env vars
- Unit tests confirm credential issuance TTL and scope constraints
- Logs and error payloads do not expose raw credentials
Phase 4: Frontend Contract Alignment
4.1 Update event parsing
- Update
apps/lib/core/chat/ag_ui_event.dart - Remove active wire parsing paths that depend on
ui_schema - Parse tool event
ui_hintsdirectly from updated payload contract - Parse structured
resultinstead of string-only assumptions
4.2 Update history parsing and cache
- Update
apps/lib/core/chat/chat_history_repository.dart - Align cached history format with the new backend history response shape
- Ensure history replay can rebuild tool UI items from backend-provided tool metadata/UI payload
4.3 Update chat service and item models
- Update
apps/lib/core/chat/ag_ui_service.dart - Ensure SSE handling matches the new tool event contract
- Update
apps/lib/core/chat/chat_list_item.dart - Remove item model assumptions that a rendered UI payload must be named
uiSchema
4.4 Update rendering path
- Update
apps/lib/features/chat/presentation/bloc/chat_bloc_events.dart - Ensure tool results become visible UI items through direct tool payloads
- Update
apps/lib/features/home/presentation/widgets/home_chat_item_renderer.dart - Continue reusing the existing renderer component if it still fits the new input shape
- Update
apps/lib/shared/widgets/ui_schema/ui_schema_renderer.dartonly as needed to accept the new direct tool UI input contract
4.5 Phase 4 verification
- Frontend tests confirm SSE tool event parsing without
ui_schema - Frontend tests confirm history replay rebuilds tool UI correctly
- Frontend tests confirm refresh/reload still shows prior tool UI consistently
Phase 5: Cleanup, Regression Tests, And Final Validation
5.1 Backend test updates
- Update
backend/tests/unit/core/agentscope/events/test_store.py - Update
backend/tests/unit/core/agentscope/events/test_agui_codec.py - Update
backend/tests/unit/core/agentscope/runtime/test_stage_emitter.py - Update
backend/tests/unit/core/agentscope/runtime/test_tasks.py - Update
backend/tests/unit/v1/agent/test_utils.py - Update
backend/tests/unit/schemas/agent/test_runtime_models.py - Add tests for CLI adapter, command router, and tool post-processing
- Add tests for controlled credential issuance and queue transport
5.2 Frontend test updates
- Update
apps/test/core/chat/ag_ui_event_test.dart - Update
apps/test/features/chat/presentation/bloc/chat_bloc_test.dart - Add tests for history repository if needed by the new replay contract
5.3 Remove obsolete code paths
- Remove worker
ui_hintsusage from runtime/event/history code paths - Remove active
ui_schemacontract usage from backend response shaping (N/A - ui_schema is still used as wire format) - Remove old direct
custom/*.pytool runtime wiring - Remove any parsing logic that assumes
ToolResponsecarries full ToolAgentOutput JSON - Remove dead compatibility helpers only after replacement path is verified
5.4 Run verification commands
- Run relevant backend unit tests with
uv run pytest ... - Run relevant frontend tests
- Run backend lint checks required for touched files
- Run backend type checks required for touched files
- If skill registration/package wiring changed, run a focused smoke check of the CLI-backed tool path
5.5 Final acceptance audit against PRD
ui_hints → ui_schemacompilation path is preserved (onlyui_hintssource changes from worker to tool)WorkerAgentOutputno longer hasui_hints/historytool UI replay compilesmetadata.tool_agent_output.ui_hintstoui_schemaToolResponsecarries only projected result text- Tool post-processor generates full
ToolAgentOutput ToolAgentOutput.resultis structured and machine-orientedmessage.contentis the full JSON text projection ofresult- CLI uses whitelist router and no shell execution path
- Chat and automation both use controlled credential injection, not
owner_idas credential - AgentScope skills are registered from project skill assets
- Hot path and cold path tool context are unified
- Frontend receives
ui_schemafromTOOL_CALL_RESULTand history - Relevant docs, tests, lint, and type checks are updated
Suggested First Implementation Slice
- Complete Phase 0 only
- Do not start backend runtime refactor until Phase 0 contract text is committed and reviewed
Progress Log
- Phase 0 complete
- Phase 1 complete
- Phase 2 complete
- Phase 3 complete
- Phase 4 complete
- Phase 5 complete