mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-03 12:49:30 +08:00
Auto capability (agents/auto/) gains a three-stage agent loop: ANALYZING (one LLM call, streamed as thinking) -> DELEGATING (router emits delegate_to_<cap> tool calls or atomic tool calls, with bounded retries and a same-cap quota) -> SYNTHESIZING (final inline answer). Sub-capability events flow through forward_events with call_id tagging so conversation history keeps only Auto's own synthesis. New chat-mountable tools: - ask_user: pauses the turn for 1-3 structured questions, frontend renders a card the user navigates and submits in one batch - web_fetch: HTTP + readable-content extraction with strict scheme/private-IP/size guards (pre-flight + post-redirect) - write_note: replaces save_to_notebook; append (new record) and edit (existing record by id) modes - list_notebook: read-only index / drill-down listing; only mounted when the user has notebooks - github_query: read-only ``gh`` CLI wrapper (pr/issue/run/repo plus GET-only api); no mutation verbs reachable Updates chat agentic_pipeline.py + agentic_chat.yaml (en/zh) to the new tool surface and source-inventory contract, refits tools/builtin/__init__.py as the single place to register chat-mounted tools and their argument-augmentation wrappers, and tightens core stream + tool_protocol around tool-result metadata. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
72 lines
1.9 KiB
Python
72 lines
1.9 KiB
Python
"""
|
|
Stream Event Protocol
|
|
=====================
|
|
|
|
Defines the unified streaming event format used by all tools, capabilities,
|
|
and plugins to communicate progress and results to consumers (CLI, WebSocket, SDK).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass, field
|
|
from enum import Enum
|
|
import time
|
|
from typing import Any
|
|
|
|
|
|
class StreamEventType(str, Enum):
|
|
"""All possible event types in a streaming session."""
|
|
|
|
STAGE_START = "stage_start"
|
|
STAGE_END = "stage_end"
|
|
THINKING = "thinking"
|
|
OBSERVATION = "observation"
|
|
CONTENT = "content"
|
|
TOOL_CALL = "tool_call"
|
|
TOOL_RESULT = "tool_result"
|
|
PROGRESS = "progress"
|
|
SOURCES = "sources"
|
|
RESULT = "result"
|
|
ERROR = "error"
|
|
SESSION = "session"
|
|
SESSION_META = "session_meta"
|
|
DONE = "done"
|
|
|
|
|
|
@dataclass
|
|
class StreamEvent:
|
|
"""
|
|
A single streaming event emitted during a chat turn.
|
|
|
|
Attributes:
|
|
type: The semantic kind of this event.
|
|
source: Which tool / capability / plugin produced it (e.g. "deep_solve").
|
|
stage: Current stage within the source (e.g. "planning").
|
|
content: Human-readable text payload.
|
|
metadata: Arbitrary structured data (tool args, sources, metrics, …).
|
|
timestamp: Unix epoch seconds when the event was created.
|
|
"""
|
|
|
|
type: StreamEventType
|
|
source: str = ""
|
|
stage: str = ""
|
|
content: str = ""
|
|
metadata: dict[str, Any] = field(default_factory=dict)
|
|
session_id: str = ""
|
|
turn_id: str = ""
|
|
seq: int = 0
|
|
timestamp: float = field(default_factory=time.time)
|
|
|
|
def to_dict(self) -> dict[str, Any]:
|
|
return {
|
|
"type": self.type.value,
|
|
"source": self.source,
|
|
"stage": self.stage,
|
|
"content": self.content,
|
|
"metadata": self.metadata,
|
|
"session_id": self.session_id,
|
|
"turn_id": self.turn_id,
|
|
"seq": self.seq,
|
|
"timestamp": self.timestamp,
|
|
}
|