跳转至

Context API

AgentContext

属性

属性 类型 描述
session_id str 会话ID
trace_id str 追踪ID
message_id str 消息ID
parent_message_id str 父消息ID
current_agent_id str 当前Agent ID
agent_runtime_state AgentRuntimeState Agent 运行时状态

方法

emit_chunk

async def emit_chunk(
    self,
    event: Union[StreamChunkEvent, str],
    event_type: Optional[str] = None,
) -> None:
    """发送流式文本片段"""

emit_state

async def emit_state(
    self,
    event: Union[StateChangeEvent, str],
    event_type: Optional[str] = None,
) -> None:
    """发送状态更新"""

emit_artifact

async def emit_artifact(
    self,
    event: Union[ArtifactEvent, str],
    event_type: Optional[str] = None,
) -> None:
    """发送产物/附件"""

ask_user

async def ask_user(
    self,
    event: Union[AskUserEvent, str],
) -> dict:
    """向用户发送等待输入请求"""

call_agent

async def call_agent(
    self,
    target_agent_type: str,
    content: object,
    wait_for_reply: bool = True,
    **kwargs,
) -> dict:
    """调用其他Agent"""

dispatch_group

async def dispatch_group(
    self,
    tasks: list[dict],
    wait_for_reply: bool = True,
    **kwargs,
) -> dict:
    """分发任务组"""

collect_group_results

async def collect_group_results(
    self,
    task_group_id: str,
) -> dict:
    """收集任务组结果"""

get_active_workers

async def get_active_workers(self) -> Dict[str, Any]:
    """获取集群中所有活跃的 worker"""

flush_to_history

async def flush_to_history(self) -> None:
    """将当前会话历史刷新到持久化存储"""

check_cancelled

async def check_cancelled(self) -> None:
    """如果任务已被取消则抛出 asyncio.CancelledError"""

is_cancel_requested

def is_cancel_requested(self) -> bool:
    """返回任务是否已被请求取消"""

update_execution_state

async def update_execution_state(self, status: str) -> None:
    """更新当前执行状态"""