mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-24 22:53:37 +00:00
AgentLab:可视化 Agent 编排实验台
在画布上拖拽编排 agent 工作流,并实时看着它执行。 后端 FastAPI + LangGraph:把画布 JSON 编译成 StateGraph,15 种节点 (模型/Agent/多Agent、工具/沙箱、分支/循环/子图、记忆/检索/整形、 人工介入/结构校验)。选 LangGraph 是因为可视化编排真正难的是暂停、 恢复和回放,而 checkpointer + interrupt() 正好把这几件事做在了底层。 前端 React + React Flow:节点元数据驱动属性面板与连接桩,运行时 节点高亮、边流动画、卡片内流式 token 全部由同一份事件流驱动。 关键实现: - Agent 内工具审批用 @task 缓存模型调用,interrupt 重放时不重复计费 - 沙箱保持只读根文件系统,代码经 exec+base64 写入(put_archive 会被 只读容器拒绝),断网、非 root、内存/CPU/超时限额 - 检索为向量与 BM25 混合,本地哈希 embedding 零配置可用 - 分支条件走 AST 白名单求值器;HTTP 工具逐 IP 拦截内网与元数据地址 - Mock provider 让无 API Key 也能跑通完整链路 7 个内置模板全部冒烟通过,含真实模型端到端验证。
This commit is contained in:
@@ -0,0 +1,151 @@
|
||||
export type NodeType =
|
||||
| 'input' | 'output' | 'llm' | 'agent' | 'supervisor' | 'tool' | 'code'
|
||||
| 'branch' | 'loop' | 'subgraph' | 'memory' | 'retrieve' | 'transform'
|
||||
| 'human' | 'validate'
|
||||
|
||||
export interface GraphNode {
|
||||
id: string
|
||||
type: NodeType
|
||||
position: { x: number; y: number }
|
||||
data: { label?: string; description?: string; config: Record<string, any> }
|
||||
}
|
||||
|
||||
export interface GraphEdge {
|
||||
id?: string
|
||||
source: string
|
||||
target: string
|
||||
sourceHandle?: string | null
|
||||
targetHandle?: string | null
|
||||
label?: string
|
||||
}
|
||||
|
||||
export interface GraphSpec {
|
||||
nodes: GraphNode[]
|
||||
edges: GraphEdge[]
|
||||
viewport?: Record<string, any>
|
||||
defaults?: Record<string, any>
|
||||
}
|
||||
|
||||
export interface Workflow {
|
||||
id: string
|
||||
name: string
|
||||
description: string
|
||||
graph: GraphSpec
|
||||
tags: string[]
|
||||
version: number
|
||||
is_template: boolean
|
||||
run_count?: number
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
export type RunStatus =
|
||||
| 'queued' | 'running' | 'interrupted' | 'succeeded' | 'failed' | 'cancelled'
|
||||
|
||||
export interface Run {
|
||||
id: string
|
||||
workflow_id: string | null
|
||||
workflow_name: string
|
||||
status: RunStatus
|
||||
input: Record<string, any>
|
||||
output: Record<string, any>
|
||||
error: string | null
|
||||
usage: Record<string, any>
|
||||
created_at?: string
|
||||
started_at?: string
|
||||
finished_at?: string
|
||||
}
|
||||
|
||||
export interface RunEvent {
|
||||
seq: number
|
||||
type: string
|
||||
node_id: string | null
|
||||
ts: number
|
||||
data: Record<string, any>
|
||||
replay?: boolean
|
||||
}
|
||||
|
||||
export interface Approval {
|
||||
id: string
|
||||
run_id: string
|
||||
node_id: string
|
||||
mode: 'approve' | 'input' | 'edit'
|
||||
title: string
|
||||
payload: Record<string, any>
|
||||
status: string
|
||||
response: Record<string, any>
|
||||
created_at?: string
|
||||
}
|
||||
|
||||
export interface Provider {
|
||||
id: string
|
||||
name: string
|
||||
kind: string
|
||||
base_url: string | null
|
||||
default_model: string | null
|
||||
models: { id: string; label?: string; context?: number; pricing?: any }[]
|
||||
enabled: boolean
|
||||
extra: Record<string, any>
|
||||
api_key_masked: string
|
||||
has_key: boolean
|
||||
}
|
||||
|
||||
export interface ToolInfo {
|
||||
id: string
|
||||
name: string
|
||||
description: string
|
||||
category: string
|
||||
source: 'builtin' | 'custom' | 'mcp'
|
||||
dangerous: boolean
|
||||
schema: Record<string, any>
|
||||
}
|
||||
|
||||
export interface Skill {
|
||||
id: string
|
||||
name: string
|
||||
description: string
|
||||
instructions: string
|
||||
examples: { input?: string; output?: string }[]
|
||||
suggested_tools: string[]
|
||||
tags: string[]
|
||||
enabled: boolean
|
||||
}
|
||||
|
||||
export interface MemoryItem {
|
||||
id: string
|
||||
scope: string
|
||||
kind: string
|
||||
content: string
|
||||
importance: number
|
||||
use_count: number
|
||||
meta: Record<string, any>
|
||||
created_at?: string
|
||||
}
|
||||
|
||||
export interface KbDocument {
|
||||
id: string
|
||||
collection: string
|
||||
title: string
|
||||
source: string
|
||||
mime: string
|
||||
chunk_count: number
|
||||
created_at?: string
|
||||
}
|
||||
|
||||
export interface ValidationIssue {
|
||||
level: 'error' | 'warning'
|
||||
node_id?: string | null
|
||||
edge_id?: string | null
|
||||
message: string
|
||||
}
|
||||
|
||||
/** 单个节点在一次运行中的实时状态,驱动画布上的高亮。 */
|
||||
export interface NodeRuntime {
|
||||
status: 'idle' | 'running' | 'done' | 'failed' | 'waiting' | 'skipped'
|
||||
durationMs?: number
|
||||
preview?: any
|
||||
error?: string
|
||||
tokens?: string
|
||||
thinking?: string
|
||||
toolCalls?: { tool: string; args?: any; result?: string; ok?: boolean }[]
|
||||
}
|
||||
Reference in New Issue
Block a user