agentleFS
shyftlabsshyftlabs/continuum/.claude/skills/continuum-streaming/SKILL.md

continuum-streaming

Skill84 starsChanged 6 months agoApache-2.0View on GitHub

Stream tokens, tool calls, handoffs, and memory events out of a Continuum agent in real time using `runner.run_stream()` and the `EventType` enum. Invoke when the user asks "stream tokens to UI", "websocket chat", "live progress", "see tool execution as it happens", or anything that needs token-by-token output.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Don't expect await runner.run_stream(agent, ...) — run_stream is an async generator.

    line 142
  2. Very specific:

    Don't accumulate RUN_END.data["usage"] from individual deltas — it's reported once at the end.

    line 144
  3. Very specific:

    Don't write to the websocket inside CONTENT_DELTA without a flush on every chunk.

    line 146
  4. Very specific:

    Don't rely on event.timestamp ordering across events from different agents in a workflow — they may interleave.

    line 148

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Continuum Streaming Skill

Authoritative sources: docs/agent.md §3 and the EventType enum in continuum/agent/types.py.


Imports

from continuum.agent import AgentRunner
from continuum.agent.types import EventType, AgentEvent

Smallest possible stream

runner = AgentRunner()

async for ev in runner.run_stream(agent, "Tell me a story", user_id="u1", session_id="s1"):
    if ev.type == EventType.CONTENT_DELTA:
        print(ev.data["content"], end="", flush=True)

run_stream() returns an AsyncIterator[AgentEvent]. Every event carries: type: EventType, agent_name: str, run_id: str, data: dict, timestamp, trace_id, span_id.


Full event reference

EventTypeFiresevent.data keys
RUN_STARTRun beginsagent_name, input_preview
RUN_ENDRun completesstatus, latency_ms, usage
RUN_ERRORRun failserror, error_type
AGENT_STARTEach agent (incl. handoff target) startsagent_name
AGENT_ENDEach agent endsagent_name, status
CONTENT_DELTALLM token chunkscontent (partial text)
CONTENT_COMPLETELLM emits a full assistant messagecontent
TOOL_CALL_STARTA tool is about to runtool_name, arguments
TOOL_CALL_ENDTool returned successfullytool_name, result
TOOL_CALL_ERRORTool raisedtool_name, error
HANDOFF_STARTSource agent invoking the handoff toolfrom_agent, to_agent, reason
HANDOFF_ENDTarget agent finishedfrom_agent, to_agent
HANDOFF_RETURNControl returned to source (return_to_parent=True)from_agent, to_agent
MEMORY_RETRIEVALLong-term memories injected into promptcount, query
MEMORY_STORAGENew memories stored after the turncount
WORKFLOW_STEPWorkflow agent advancedstep, agent_name
LOOP_ITERATIONLoopAgent completed an iterationiteration, output

Common patterns

Plain console with tool indicators

async for ev in runner.run_stream(agent, "..."):
    if ev.type == EventType.CONTENT_DELTA:
        print(ev.data["content"], end="", flush=True)
    elif ev.type == EventType.TOOL_CALL_START:
        print(f"\n[tool: {ev.data['tool_name']} ...]", flush=True)
    elif ev.type == EventType.TOOL_CALL_END:
        print(" ✓", flush=True)
    elif ev.type == EventType.RUN_END:
        print()

Stream to a websocket

async def stream_to_ws(ws, agent, user_msg, user_id):
    async for ev in AgentRunner().run_stream(agent, user_msg, user_id=user_id):
        if ev.type == EventType.CONTENT_DELTA:
            await ws.send_text(ev.data["content"])
        elif ev.type == EventType.TOOL_CALL_START:
            await ws.send_json({"event": "tool_start", "tool": ev.data["tool_name"]})
        elif ev.type == EventType.TOOL_CALL_END:
            await ws.send_json({"event": "tool_end", "tool": ev.data["tool_name"]})
        elif ev.type == EventType.HANDOFF_START:
            await ws.send_json({"event": "handoff",
                                "from": ev.data["from_agent"],
                                "to":   ev.data["to_agent"]})
        elif ev.type == EventType.RUN_END:
            await ws.send_json({"event": "done",
                                "usage": ev.data.get("usage", {})})

Stream as Server-Sent Events (FastAPI)

from fastapi import FastAPI
from fastapi.responses import StreamingResponse

@app.post("/chat")
async def chat(message: str, user_id: str):
    async def gen():
        async for ev in AgentRunner().run_stream(agent, message, user_id=user_id):
            if ev.type == EventType.CONTENT_DELTA:
                yield f"data: {ev.data['content']}\n\n"
            elif ev.type == EventType.RUN_END:
                yield "event: done\ndata: {}\n\n"
    return StreamingResponse(gen(), media_type="text/event-stream")

Collecting full content from a stream

buf = []
async for ev in runner.run_stream(agent, "..."):
    if ev.type == EventType.CONTENT_DELTA:
        buf.append(ev.data["content"])
content = "".join(buf)

Behaviour notes

  • During a tool call, CONTENT_DELTA pauses. The next chunks will fire after TOOL_CALL_END — when the LLM resumes generation.
  • During a handoff, the target agent emits its own AGENT_START and CONTENT_DELTA events under the same run_id. Use agent_name on the event (or your own state) to attribute output.
  • Streaming respects context-window compression — by the time CONTENT_DELTA fires, the prompt has already been compressed if needed.

Don't

  • Don't expect await runner.run_stream(agent, ...) — run_stream is an async generator. Use async for ev in runner.run_stream(...).
  • Don't accumulate RUN_END.data["usage"] from individual deltas — it's reported once at the end.
  • Don't write to the websocket inside CONTENT_DELTA without a flush on every chunk; ws frames buffer otherwise.
  • Don't rely on event.timestamp ordering across events from different agents in a workflow — they may interleave.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.