Skip to content

feat(agentapi): stream coalesced tool-call events in SSE chat responses - #98

Closed
fepfitra wants to merge 13 commits into
anvie:mainfrom
fepfitra:feat/agentapi-tool-log
Closed

feat(agentapi): stream coalesced tool-call events in SSE chat responses#98
fepfitra wants to merge 13 commits into
anvie:mainfrom
fepfitra:feat/agentapi-tool-log

Conversation

@fepfitra

@fepfitra fepfitra commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Problem

The agentapi streaming chat endpoint (/plugin/agentapi/v1/chat/completions with stream: true) only forwards llm_response_chunk and turn_complete events. Streaming clients (e.g. the pitura-dashboard) can show the agent's text but have NO visibility into what the agent is DOING (running bash, editing files, searching the web). Tool execution is a black box during long agent turns.

Fix

Subscribe to the existing tool_executed event stream, coalesce tool calls per session into a 5-second window (mirroring the Telegram channel pattern from PR #95), and emit inline SSE events while the stream is open:

data: {"type":"tool","tool_name":"bash (2x), python (1x)","has_error":false}
  • A 100-tool loop collapses to a handful of lines, not one per call.
  • has_error surfaces failures (client can style them ⚠️).
  • The type: "tool" field distinguishes tool events from normal choices[].delta.content chunks.
  • Cleanup: tool_executed is unsubscribed in the same finally block as the other events.

Verification

python -c 'import ast; ast.parse(...)' — syntax OK. Live-tested against the dashboard after restart: tool calls appear as compact chips in the chat while the agent works.

fepfitra added 13 commits August 1, 2026 08:57
Mirror the existing agent clone flow: copy type and config into a new
disconnected workplace. Tunnel connectors are not copied - the clone
needs its own pairing.

- models/mixins/workplaces.py: clone_workplace() mixin
- routes/workplaces.py: POST /api/workplaces/<id>/clone
- templates/workplace_detail.html: Clone button + modal
Deleting an agent rmtrees its chat.db but the AgentChatManager kept the
cached AgentChatDB instance. Recreating an agent with the same id returned
that stale instance; if its persistent connection had been closed, the
lazy _get_conn reopens a fresh empty chat.db (mode=rwc) and _init_tables()
never runs for it → 'no such table: chat_sessions' on first query.

Add AgentChatManager.drop() which closes and removes the cached instance,
and call it from all three agent-delete paths (API route, super-agent
tool, CLI). Add regression tests covering the stale-cache failure and the
drop-then-recreate recovery.
…cking vision payloads

python-requests default UA is blocked by Cloudflare WAF (error 1010) for
large image payloads, while small text requests pass. Add a Chrome UA so
multimodal image requests reach OpenAI-compatible endpoints behind CF.
…d super agent

Previously ANY is_super=1 agent bypassed the agent_skills allowlist check
in use_skill, letting every super agent lazy-load any skill (e.g. exa-search)
without an explicit assignment.

Now the exemption applies only to the agent named by the super_agent_id
setting (DB app_settings), so other super agents must have the skill in
their agent_skills rows like everyone else. No hardcoding — the setting
already exists and defaults to kremas.
Lazy skills load only from agent_skills for non-designated agents; only
the super_agent_id agent gets blanket access.
Subscribe to tool_executed events, coalesce per session into a 5s window
(mirrors the Telegram channel pattern), and emit inline SSE events like
{"type":"tool","tool_name":"bash (2x)","has_error":false} so
streaming chat clients can show what the agent is doing.
fepfitra added a commit to fepfitra/evonic that referenced this pull request Aug 5, 2026
@fepfitra

fepfitra commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Closing: PR was polluted with 12 unrelated commits from merge/our-fixes (clone-workplace, cache-invalidation, telegram-notify, llm_client UA, skill-allowlist). Reopening as a clean single-commit PR.

@fepfitra fepfitra closed this Aug 5, 2026
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