19e273a9e6
- calendar: split write → create/read/update/delete/share - contacts: rename lookup → read - memory: merge write+forget → update (unified action field in operations) - Remove all alias/normalization logic from adapter and handlers - Update tool_postprocessor ui_hints builders to canonical keys - Remove frontend legacy TOOL_CALL_START/ARGS/END events and ToolCallItem - Update SKILL.md files and protocol docs - Update tests and settings screens
3.2 KiB
3.2 KiB
Debug Session: Tool Credential Injection Issue
Date
2026-04-22
Context
After completing the skills+CLI refactor, running live integration tests revealed tool credential injection issues.
Commits Made
4d55df4- refactor: unify skills+cli runtime and streamline ag-ui flowef931ee- chore: clean up legacy tool/UI code paths and remove unused events91077a9- fix: pass tool_call_id to parse_tool_agent_output for proper payload resolution
Test Execution
CLI_SKILLS_LIVE_TEST=1 TEST_USER_ID="f6f4bc6b-f525-434e-81b6-38eeef9b89a8" \
AGENT_LIVE_BASE_URL="http://localhost:5775" \
uv run pytest backend/tests/integration/test_cli_skills_live.py::test_calendar_read_skill_queries_db -v -s
Error Found
From logs/errors/worker-agent.error.log:
"error": "tool credential not found in runtime context",
"tool_name": "project_cli"
Full stack trace shows:
invoke_cli_toolcalls_resolve_owner_id()_resolve_owner_id()callsget_tool_credential()get_tool_credential()returnsNone- Raises
TokenValidationError("tool credential not found in runtime context")
Root Cause Analysis
The tool credential is set via context variable tool_credential but is not being injected into the runtime context before tool execution.
Key Files
backend/src/core/auth/tool_credential_context.py- ContextVar for tool credentialbackend/src/core/agentscope/tools/cli/adapter.py- Callsget_tool_credential()backend/src/core/agentscope/runtime/runner.py- Should inject credential before tool execution
Expected Flow
- Runner receives run request with
owner_id - Runner creates tool credential using
ToolCredentialIssuer - Runner sets credential via
set_tool_credential(credential) - Tool execution reads via
get_tool_credential() - After execution, credential is cleared
Missing Implementation
The credential injection logic needs to be added to runner.py around the worker stage execution.
Secondary Error
When tool credential fails, the error response causes a DB insert error:
invalid input for query argument $5: {'status': 'failure', ...} (expected str, got dict)
This is because content field receives a dict instead of str. Fixed in store.py by ensuring proper serialization, but the root cause is the missing credential.
Next Steps
- Find where tool credential should be set in runtime
- Add credential issuance in runner before tool execution
- Ensure credential is passed through task queue or generated in worker
- Restart backend service with new code
- Re-run integration tests
Database State
system_agents.config.enabled_skills: Correctly uses["calendar", "contacts"]automation_jobs.config: No longer hasenabled_tools- User ID for testing:
f6f4bc6b-f525-434e-81b6-38eeef9b89a8
Files Modified
backend/src/core/agentscope/runtime/stage_emitter.py- Fixedtool_call_idpassingbackend/tests/integration/test_cli_skills_live.py- Added live integration tests
Remaining Work
- Fix tool credential injection in runtime
- Verify calendar read/write works end-to-end
- Verify contacts lookup works end-to-end
- Verify memory write via automation works
- Run full test suite after fixes