fusion-agent-studio 0.18.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agent_runtime/__init__.py +279 -0
- agent_runtime/_runtime_checkpoint.py +249 -0
- agent_runtime/_runtime_dynamic_tools.py +218 -0
- agent_runtime/_runtime_helpers.py +258 -0
- agent_runtime/_runtime_nodes.py +3357 -0
- agent_runtime/_runtime_safety.py +311 -0
- agent_runtime/acp_client.py +241 -0
- agent_runtime/agent_api.py +216 -0
- agent_runtime/agent_commodity.py +225 -0
- agent_runtime/agent_definition.py +415 -0
- agent_runtime/agent_marketplace.py +335 -0
- agent_runtime/agent_package.py +629 -0
- agent_runtime/agent_platform/__init__.py +9 -0
- agent_runtime/agent_platform/capabilities.py +340 -0
- agent_runtime/agent_platform/door.py +619 -0
- agent_runtime/agent_platform/publish_registry.py +57 -0
- agent_runtime/agent_platform/templates.py +146 -0
- agent_runtime/agent_platform/webhooks.py +200 -0
- agent_runtime/agent_platform/yaml_compiler.py +213 -0
- agent_runtime/agent_templates.py +404 -0
- agent_runtime/agent_version.py +139 -0
- agent_runtime/api_agents_platform.py +718 -0
- agent_runtime/api_cluster_ops.py +156 -0
- agent_runtime/api_marketplace.py +166 -0
- agent_runtime/api_server.py +3219 -0
- agent_runtime/apikey_manager.py +286 -0
- agent_runtime/artifact_bridge.py +302 -0
- agent_runtime/artifact_channel.py +53 -0
- agent_runtime/artifact_tools.py +726 -0
- agent_runtime/asset_registry.py +144 -0
- agent_runtime/audit_logger.py +294 -0
- agent_runtime/auth_middleware.py +119 -0
- agent_runtime/aware_engine.py +316 -0
- agent_runtime/budget_engine.py +152 -0
- agent_runtime/builtin_agents.py +159 -0
- agent_runtime/bundle_package.py +487 -0
- agent_runtime/capability_tools.py +233 -0
- agent_runtime/chat_engine.py +789 -0
- agent_runtime/cli.py +670 -0
- agent_runtime/cluster_server.py +574 -0
- agent_runtime/code_sandbox.py +478 -0
- agent_runtime/compactor.py +77 -0
- agent_runtime/confirmation_policy.py +137 -0
- agent_runtime/connectors.py +299 -0
- agent_runtime/context.py +329 -0
- agent_runtime/cowork_manager.py +195 -0
- agent_runtime/daemon_server.py +5180 -0
- agent_runtime/data_ingestion.py +992 -0
- agent_runtime/debugger.py +142 -0
- agent_runtime/delivery_channel.py +43 -0
- agent_runtime/deployer.py +107 -0
- agent_runtime/dispatchers/__init__.py +59 -0
- agent_runtime/dispatchers/agent.py +2022 -0
- agent_runtime/dispatchers/artifact.py +149 -0
- agent_runtime/dispatchers/base.py +26 -0
- agent_runtime/dispatchers/bundle.py +85 -0
- agent_runtime/dispatchers/chat.py +267 -0
- agent_runtime/dispatchers/commodity.py +197 -0
- agent_runtime/dispatchers/deploy.py +176 -0
- agent_runtime/dispatchers/eval.py +58 -0
- agent_runtime/dispatchers/flow.py +395 -0
- agent_runtime/dispatchers/history.py +102 -0
- agent_runtime/dispatchers/infra.py +1111 -0
- agent_runtime/dispatchers/knowledge.py +364 -0
- agent_runtime/dispatchers/marketplace.py +181 -0
- agent_runtime/dispatchers/mcp.py +281 -0
- agent_runtime/dispatchers/memory.py +274 -0
- agent_runtime/dispatchers/planner.py +204 -0
- agent_runtime/dispatchers/playground.py +97 -0
- agent_runtime/dispatchers/plugin.py +175 -0
- agent_runtime/dispatchers/reviewer.py +102 -0
- agent_runtime/dispatchers/safety.py +191 -0
- agent_runtime/dispatchers/session.py +221 -0
- agent_runtime/dispatchers/skills.py +274 -0
- agent_runtime/dispatchers/subagent.py +415 -0
- agent_runtime/dispatchers/team.py +424 -0
- agent_runtime/dispatchers/teams.py +664 -0
- agent_runtime/dispatchers/trainer.py +212 -0
- agent_runtime/dispatchers/workflow.py +184 -0
- agent_runtime/durable_roster.py +270 -0
- agent_runtime/ecom_client.py +128 -0
- agent_runtime/errors.py +288 -0
- agent_runtime/eval_runner.py +500 -0
- agent_runtime/event_tree.py +336 -0
- agent_runtime/executor.py +56 -0
- agent_runtime/exporter.py +216 -0
- agent_runtime/file_checkpoint.py +247 -0
- agent_runtime/flow_store.py +273 -0
- agent_runtime/fmp_router.py +349 -0
- agent_runtime/fsb_client.py +122 -0
- agent_runtime/funnels.py +3 -0
- agent_runtime/fusion_code_bridge.py +183 -0
- agent_runtime/fusion_memory_adapter.py +356 -0
- agent_runtime/graph.py +483 -0
- agent_runtime/graph_editor.py +355 -0
- agent_runtime/guard_client.py +391 -0
- agent_runtime/guardrails_client.py +120 -0
- agent_runtime/hooks.py +4 -0
- agent_runtime/i18n.py +155 -0
- agent_runtime/identity_integration.py +174 -0
- agent_runtime/inbox_consumer.py +204 -0
- agent_runtime/inspector.py +153 -0
- agent_runtime/json_schema.py +146 -0
- agent_runtime/kernel_wiring.py +330 -0
- agent_runtime/knowledge_base.py +579 -0
- agent_runtime/knowledge_engine.py +557 -0
- agent_runtime/lifecycle_consumer.py +120 -0
- agent_runtime/llm_gateway.py +992 -0
- agent_runtime/loop_watchdog.py +152 -0
- agent_runtime/loopback.py +36 -0
- agent_runtime/mcp_server.py +410 -0
- agent_runtime/memory_engine.py +1198 -0
- agent_runtime/memory_pack.py +89 -0
- agent_runtime/memory_skill_sync.py +118 -0
- agent_runtime/metrics_engine.py +317 -0
- agent_runtime/offline_reviewer.py +203 -0
- agent_runtime/orchestrator.py +802 -0
- agent_runtime/parked_runs.py +187 -0
- agent_runtime/path_scope.py +131 -0
- agent_runtime/paths.py +14 -0
- agent_runtime/peer_notify.py +70 -0
- agent_runtime/permission_cards.py +62 -0
- agent_runtime/permissions.py +3 -0
- agent_runtime/persistence.py +1423 -0
- agent_runtime/persona.py +481 -0
- agent_runtime/persona_gate.py +141 -0
- agent_runtime/persona_pack.py +259 -0
- agent_runtime/planner.py +509 -0
- agent_runtime/playbook_store.py +136 -0
- agent_runtime/playground.py +110 -0
- agent_runtime/plaza.py +491 -0
- agent_runtime/plugin_bridge.py +112 -0
- agent_runtime/proctitle.py +28 -0
- agent_runtime/prompt_templates.py +257 -0
- agent_runtime/protocol_plane.py +172 -0
- agent_runtime/rag_pipeline.py +570 -0
- agent_runtime/rate_limiter.py +180 -0
- agent_runtime/resident_reviewer.py +193 -0
- agent_runtime/resource_lease.py +271 -0
- agent_runtime/review_triage.py +169 -0
- agent_runtime/reviewer_packs.py +459 -0
- agent_runtime/rpc_auth.py +252 -0
- agent_runtime/rpc_bridge.py +387 -0
- agent_runtime/run_artifacts.py +191 -0
- agent_runtime/run_history.py +169 -0
- agent_runtime/run_registry.py +121 -0
- agent_runtime/runtime.py +1520 -0
- agent_runtime/safety.py +812 -0
- agent_runtime/sandbox_router.py +112 -0
- agent_runtime/sdk/__init__.py +84 -0
- agent_runtime/sdk/agent.py +210 -0
- agent_runtime/sdk/client.py +156 -0
- agent_runtime/sdk/tool.py +102 -0
- agent_runtime/seat_pack.py +127 -0
- agent_runtime/seats/delivery_seats.yaml +241 -0
- agent_runtime/session_manager.py +337 -0
- agent_runtime/session_store.py +259 -0
- agent_runtime/shell_registry.py +327 -0
- agent_runtime/skill_drafter.py +314 -0
- agent_runtime/skill_permissions.py +86 -0
- agent_runtime/skills_store.py +414 -0
- agent_runtime/style_manager.py +175 -0
- agent_runtime/sub_graph.py +69 -0
- agent_runtime/subagent.py +853 -0
- agent_runtime/subagent_defs.py +232 -0
- agent_runtime/subagent_sessions.py +314 -0
- agent_runtime/swarm_router.py +461 -0
- agent_runtime/task_board.py +64 -0
- agent_runtime/task_executor.py +321 -0
- agent_runtime/task_store.py +1168 -0
- agent_runtime/team_lead.py +448 -0
- agent_runtime/telemetry.py +628 -0
- agent_runtime/templates.py +697 -0
- agent_runtime/token_budget.py +175 -0
- agent_runtime/tool_pipeline.py +193 -0
- agent_runtime/training_service.py +319 -0
- agent_runtime/trajectory_writer.py +486 -0
- agent_runtime/trigger_input.py +109 -0
- agent_runtime/triggers.py +1090 -0
- agent_runtime/undo_manager.py +79 -0
- agent_runtime/variable_manager.py +105 -0
- agent_runtime/verifier.py +321 -0
- agent_runtime/worker_pool.py +209 -0
- agent_runtime/workflow_engine.py +898 -0
- agent_runtime/workspace.py +133 -0
- agent_runtime/workspace_binder.py +67 -0
- fusion_agent_studio-0.18.5.dist-info/METADATA +42 -0
- fusion_agent_studio-0.18.5.dist-info/RECORD +220 -0
- fusion_agent_studio-0.18.5.dist-info/WHEEL +5 -0
- fusion_agent_studio-0.18.5.dist-info/entry_points.txt +3 -0
- fusion_agent_studio-0.18.5.dist-info/licenses/LICENSE +190 -0
- fusion_agent_studio-0.18.5.dist-info/top_level.txt +3 -0
- server/__init__.py +18 -0
- server/fusion_mlx_client.py +633 -0
- server/fusion_rag_client.py +368 -0
- server/process_manager.py +171 -0
- tools/__init__.py +159 -0
- tools/artifact_fc_tools.py +403 -0
- tools/base.py +73 -0
- tools/browser_tools.py +394 -0
- tools/code_tools.py +162 -0
- tools/computer_use_tools.py +640 -0
- tools/cowork_tools.py +330 -0
- tools/data_tools.py +115 -0
- tools/db_tools.py +184 -0
- tools/file_tools.py +643 -0
- tools/git_tools.py +213 -0
- tools/http_tools.py +39 -0
- tools/mcp_tool.py +532 -0
- tools/memory_tools.py +164 -0
- tools/plan_tools.py +46 -0
- tools/plugin_manager.py +233 -0
- tools/registry.py +102 -0
- tools/skill_tools.py +117 -0
- tools/subagent_tool.py +131 -0
- tools/team_lead_tools.py +241 -0
- tools/terminal_tools.py +199 -0
- tools/text_tools.py +157 -0
- tools/tool_search.py +39 -0
- tools/utility_tools.py +162 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"""Agent Runtime — core engine for agent orchestration and execution."""
|
|
2
|
+
|
|
3
|
+
from .agent_marketplace import AgentMarketplace, MarketEntry
|
|
4
|
+
from .agent_package import AgentManifest, AgentPackage
|
|
5
|
+
from .agent_templates import (
|
|
6
|
+
TEMPLATES,
|
|
7
|
+
AgentTemplate,
|
|
8
|
+
get_template,
|
|
9
|
+
instantiate_template,
|
|
10
|
+
list_templates,
|
|
11
|
+
)
|
|
12
|
+
from .api_server import app as api_app
|
|
13
|
+
from .aware_engine import (
|
|
14
|
+
ASTDiffLayer,
|
|
15
|
+
AwareEngine,
|
|
16
|
+
AwareResult,
|
|
17
|
+
DebounceLayer,
|
|
18
|
+
FileEvent,
|
|
19
|
+
ModelGateLayer,
|
|
20
|
+
)
|
|
21
|
+
from .chat_engine import (
|
|
22
|
+
ChatEngine,
|
|
23
|
+
ChatEvent,
|
|
24
|
+
ChatEventType,
|
|
25
|
+
ChatMessage,
|
|
26
|
+
ChatMode,
|
|
27
|
+
ChatSession,
|
|
28
|
+
)
|
|
29
|
+
from .code_sandbox import (
|
|
30
|
+
ASTAnalysis,
|
|
31
|
+
ASTChecker,
|
|
32
|
+
CodeSandbox,
|
|
33
|
+
DiffPreview,
|
|
34
|
+
DiffResult,
|
|
35
|
+
SandboxResult,
|
|
36
|
+
)
|
|
37
|
+
from .context import AgentContext, AgentEvent, AgentEventType
|
|
38
|
+
from .daemon_server import DaemonServer, run_daemon
|
|
39
|
+
from .data_ingestion import (
|
|
40
|
+
Chunk,
|
|
41
|
+
DirectoryReader,
|
|
42
|
+
Document,
|
|
43
|
+
DocumentReader,
|
|
44
|
+
ETLPipeline,
|
|
45
|
+
FixedSizeChunker,
|
|
46
|
+
GitHubReader,
|
|
47
|
+
MarkdownChunker,
|
|
48
|
+
NotionReader,
|
|
49
|
+
PDFReader,
|
|
50
|
+
SentenceChunker,
|
|
51
|
+
WebReader,
|
|
52
|
+
)
|
|
53
|
+
from .debugger import StepDebugger
|
|
54
|
+
from .exporter import GraphExporter
|
|
55
|
+
from .fmp_router import (
|
|
56
|
+
AgentCircuitBreaker,
|
|
57
|
+
AgentInfo,
|
|
58
|
+
FMPMessageV2,
|
|
59
|
+
FMProtocol,
|
|
60
|
+
MentionRouter,
|
|
61
|
+
MessageDedup,
|
|
62
|
+
TurnManager,
|
|
63
|
+
)
|
|
64
|
+
from .funnels import LifecycleBus, LLMFunnel, ToolFunnel
|
|
65
|
+
from .fusion_code_bridge import CodeResult, CodeTask, FusionCodeBridge
|
|
66
|
+
from .fusion_memory_adapter import FusionMemoryAdapter
|
|
67
|
+
from .graph import AgentGraph, Edge, NodeConfig, NodeType
|
|
68
|
+
from .graph_editor import (
|
|
69
|
+
GraphDocument,
|
|
70
|
+
GraphEditor,
|
|
71
|
+
NodePosition,
|
|
72
|
+
ValidationIssue,
|
|
73
|
+
ValidationResult,
|
|
74
|
+
auto_layout,
|
|
75
|
+
validate_graph,
|
|
76
|
+
)
|
|
77
|
+
from .guard_client import GuardSafetyBackend
|
|
78
|
+
from .json_schema import JsonSchemaValidator
|
|
79
|
+
from .knowledge_engine import KnowledgeEngine, KnowledgeEntry
|
|
80
|
+
from .llm_gateway import GatewayResponse, LLMGateway, ModelConfig, ModelStats
|
|
81
|
+
from .memory_engine import MemoryEngine, MemoryEntry, MemoryTier
|
|
82
|
+
from .metrics_engine import (
|
|
83
|
+
InferenceMetrics,
|
|
84
|
+
MetricsEngine,
|
|
85
|
+
MetricsSummary,
|
|
86
|
+
SessionRecord,
|
|
87
|
+
)
|
|
88
|
+
from .orchestrator import (
|
|
89
|
+
AgentConfig,
|
|
90
|
+
HandoffContext,
|
|
91
|
+
MultiAgentOrchestrator,
|
|
92
|
+
OrchestrationResult,
|
|
93
|
+
)
|
|
94
|
+
from .permissions import PermissionEngine, PermissionMode, PermissionRule
|
|
95
|
+
from .persistence import AgentStore, Checkpoint
|
|
96
|
+
from .planner import ExecutionPlan, PlannerEngine, PlanStep
|
|
97
|
+
from .plaza import Plaza, PlazaChannel, PlazaMessage
|
|
98
|
+
from .prompt_templates import PromptTemplateManager
|
|
99
|
+
from .rag_pipeline import (
|
|
100
|
+
RAGConfig,
|
|
101
|
+
RAGNodeMixin,
|
|
102
|
+
RAGPipeline,
|
|
103
|
+
RAGResult,
|
|
104
|
+
VectorRetrievalStrategy,
|
|
105
|
+
)
|
|
106
|
+
from .runtime import AgentRuntime, ConditionEngine
|
|
107
|
+
from .safety import (
|
|
108
|
+
CAT_CODE_ANALYSIS,
|
|
109
|
+
CAT_CODE_EDIT,
|
|
110
|
+
CAT_DATABASE_WRITE,
|
|
111
|
+
CAT_DOC_RETRIEVAL,
|
|
112
|
+
CAT_FILE_READ,
|
|
113
|
+
CAT_FILE_WRITE,
|
|
114
|
+
CAT_GIT_PUSH,
|
|
115
|
+
CAT_KNOWLEDGE_SEARCH,
|
|
116
|
+
CAT_NETWORK_ACCESS,
|
|
117
|
+
CAT_SHELL_EXEC,
|
|
118
|
+
DiffPreviewRequest,
|
|
119
|
+
SafetyAction,
|
|
120
|
+
SafetyGateway,
|
|
121
|
+
SafetyLevel,
|
|
122
|
+
SafetyPolicy,
|
|
123
|
+
SafetyRule,
|
|
124
|
+
SafetyVerdict,
|
|
125
|
+
)
|
|
126
|
+
from .sub_graph import SubGraphRegistry
|
|
127
|
+
from .subagent import SubAgentRegistry, SubAgentReport, SubAgentRunner, SubAgentSpec
|
|
128
|
+
from .swarm_router import SwarmAgent, SwarmRouter, TaskDelegation
|
|
129
|
+
from .token_budget import TokenBudget
|
|
130
|
+
from .triggers import CronExecution, CronJob, CronManager, Webhook, WebhookManager
|
|
131
|
+
from .variable_manager import VariableManager
|
|
132
|
+
from .verifier import VerificationEngine, VerificationResult
|
|
133
|
+
|
|
134
|
+
__all__ = [
|
|
135
|
+
"AgentGraph",
|
|
136
|
+
"Edge",
|
|
137
|
+
"NodeConfig",
|
|
138
|
+
"NodeType",
|
|
139
|
+
"AgentContext",
|
|
140
|
+
"AgentEvent",
|
|
141
|
+
"AgentEventType",
|
|
142
|
+
"AgentRuntime",
|
|
143
|
+
"ConditionEngine",
|
|
144
|
+
"MultiAgentOrchestrator",
|
|
145
|
+
"AgentConfig",
|
|
146
|
+
"OrchestrationResult",
|
|
147
|
+
"HandoffContext",
|
|
148
|
+
"AgentStore",
|
|
149
|
+
"Checkpoint",
|
|
150
|
+
"GraphExporter",
|
|
151
|
+
"StepDebugger",
|
|
152
|
+
"VariableManager",
|
|
153
|
+
"JsonSchemaValidator",
|
|
154
|
+
"PromptTemplateManager",
|
|
155
|
+
"SubGraphRegistry",
|
|
156
|
+
"SubAgentRegistry",
|
|
157
|
+
"SubAgentReport",
|
|
158
|
+
"SubAgentRunner",
|
|
159
|
+
"SubAgentSpec",
|
|
160
|
+
"AgentManifest",
|
|
161
|
+
"AgentPackage",
|
|
162
|
+
"MemoryEngine",
|
|
163
|
+
"MemoryEntry",
|
|
164
|
+
"MemoryTier",
|
|
165
|
+
"FusionMemoryAdapter",
|
|
166
|
+
"GuardSafetyBackend",
|
|
167
|
+
"SafetyGateway",
|
|
168
|
+
"SafetyLevel",
|
|
169
|
+
"SafetyAction",
|
|
170
|
+
"SafetyVerdict",
|
|
171
|
+
"SafetyRule",
|
|
172
|
+
"SafetyPolicy",
|
|
173
|
+
"DiffPreviewRequest",
|
|
174
|
+
"CAT_CODE_ANALYSIS",
|
|
175
|
+
"CAT_DOC_RETRIEVAL",
|
|
176
|
+
"CAT_KNOWLEDGE_SEARCH",
|
|
177
|
+
"CAT_FILE_READ",
|
|
178
|
+
"CAT_FILE_WRITE",
|
|
179
|
+
"CAT_CODE_EDIT",
|
|
180
|
+
"CAT_SHELL_EXEC",
|
|
181
|
+
"CAT_GIT_PUSH",
|
|
182
|
+
"CAT_DATABASE_WRITE",
|
|
183
|
+
"CAT_NETWORK_ACCESS",
|
|
184
|
+
"FusionCodeBridge",
|
|
185
|
+
"CodeTask",
|
|
186
|
+
"CodeResult",
|
|
187
|
+
"api_app",
|
|
188
|
+
"AgentTemplate",
|
|
189
|
+
"TEMPLATES",
|
|
190
|
+
"list_templates",
|
|
191
|
+
"get_template",
|
|
192
|
+
"instantiate_template",
|
|
193
|
+
"GraphEditor",
|
|
194
|
+
"GraphDocument",
|
|
195
|
+
"NodePosition",
|
|
196
|
+
"ValidationResult",
|
|
197
|
+
"ValidationIssue",
|
|
198
|
+
"validate_graph",
|
|
199
|
+
"auto_layout",
|
|
200
|
+
"MetricsEngine",
|
|
201
|
+
"InferenceMetrics",
|
|
202
|
+
"SessionRecord",
|
|
203
|
+
"MetricsSummary",
|
|
204
|
+
"AgentMarketplace",
|
|
205
|
+
"MarketEntry",
|
|
206
|
+
"Document",
|
|
207
|
+
"Chunk",
|
|
208
|
+
"DocumentReader",
|
|
209
|
+
"FixedSizeChunker",
|
|
210
|
+
"SentenceChunker",
|
|
211
|
+
"MarkdownChunker",
|
|
212
|
+
"ETLPipeline",
|
|
213
|
+
"WebReader",
|
|
214
|
+
"GitHubReader",
|
|
215
|
+
"NotionReader",
|
|
216
|
+
"PDFReader",
|
|
217
|
+
"DirectoryReader",
|
|
218
|
+
"ASTChecker",
|
|
219
|
+
"DiffPreview",
|
|
220
|
+
"CodeSandbox",
|
|
221
|
+
"ASTAnalysis",
|
|
222
|
+
"DiffResult",
|
|
223
|
+
"SandboxResult",
|
|
224
|
+
"FileEvent",
|
|
225
|
+
"AwareResult",
|
|
226
|
+
"DebounceLayer",
|
|
227
|
+
"ASTDiffLayer",
|
|
228
|
+
"ModelGateLayer",
|
|
229
|
+
"AwareEngine",
|
|
230
|
+
"AgentInfo",
|
|
231
|
+
"FMPMessageV2",
|
|
232
|
+
"AgentCircuitBreaker",
|
|
233
|
+
"MessageDedup",
|
|
234
|
+
"TurnManager",
|
|
235
|
+
"MentionRouter",
|
|
236
|
+
"FMProtocol",
|
|
237
|
+
"KnowledgeEngine",
|
|
238
|
+
"KnowledgeEntry",
|
|
239
|
+
"LLMGateway",
|
|
240
|
+
"ModelConfig",
|
|
241
|
+
"ModelStats",
|
|
242
|
+
"GatewayResponse",
|
|
243
|
+
"RAGPipeline",
|
|
244
|
+
"RAGConfig",
|
|
245
|
+
"RAGResult",
|
|
246
|
+
"RAGNodeMixin",
|
|
247
|
+
"VectorRetrievalStrategy",
|
|
248
|
+
"SwarmRouter",
|
|
249
|
+
"SwarmAgent",
|
|
250
|
+
"TaskDelegation",
|
|
251
|
+
"Plaza",
|
|
252
|
+
"PlazaMessage",
|
|
253
|
+
"PlazaChannel",
|
|
254
|
+
"PlannerEngine",
|
|
255
|
+
"PlanStep",
|
|
256
|
+
"ExecutionPlan",
|
|
257
|
+
"VerificationEngine",
|
|
258
|
+
"VerificationResult",
|
|
259
|
+
"DaemonServer",
|
|
260
|
+
"run_daemon",
|
|
261
|
+
"ChatEngine",
|
|
262
|
+
"ChatSession",
|
|
263
|
+
"ChatMessage",
|
|
264
|
+
"ChatEvent",
|
|
265
|
+
"ChatEventType",
|
|
266
|
+
"ChatMode",
|
|
267
|
+
"Webhook",
|
|
268
|
+
"CronJob",
|
|
269
|
+
"CronExecution",
|
|
270
|
+
"WebhookManager",
|
|
271
|
+
"CronManager",
|
|
272
|
+
"TokenBudget",
|
|
273
|
+
"LifecycleBus",
|
|
274
|
+
"LLMFunnel",
|
|
275
|
+
"ToolFunnel",
|
|
276
|
+
"PermissionEngine",
|
|
277
|
+
"PermissionMode",
|
|
278
|
+
"PermissionRule",
|
|
279
|
+
]
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"""Checkpoint mixin — extracted from AgentRuntime (audit 0826 P2-4).
|
|
2
|
+
|
|
3
|
+
Holds checkpoint save + resume methods. Method bodies are verbatim moves;
|
|
4
|
+
AgentRuntime inherits this mixin.
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import json
|
|
9
|
+
from typing import AsyncIterator
|
|
10
|
+
|
|
11
|
+
from ._runtime_helpers import logger
|
|
12
|
+
from .context import AgentContext, AgentEvent, AgentEventType
|
|
13
|
+
from .graph import AgentGraph
|
|
14
|
+
from .variable_manager import VariableManager
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class _CheckpointMixin:
|
|
18
|
+
@staticmethod
|
|
19
|
+
def _extract_pending_tool_calls(messages: list) -> list[dict]:
|
|
20
|
+
# 审计 P1-20/E-20: 找出尾段未闭合 tool_calls — assistant 发 tool_calls
|
|
21
|
+
# 后无匹配 tool 回复. 返回该 assistant 消息的 tool_calls 列表 (空则无 pending).
|
|
22
|
+
if not messages:
|
|
23
|
+
return []
|
|
24
|
+
for msg in reversed(messages):
|
|
25
|
+
if not isinstance(msg, dict):
|
|
26
|
+
continue
|
|
27
|
+
role = msg.get("role")
|
|
28
|
+
if role == "tool":
|
|
29
|
+
# 最近一条是 tool 回复 -> 已闭合, 无 pending.
|
|
30
|
+
return []
|
|
31
|
+
if role == "assistant" and msg.get("tool_calls"):
|
|
32
|
+
# assistant tool_calls 后无 tool 回复 -> pending.
|
|
33
|
+
return msg["tool_calls"]
|
|
34
|
+
if role == "assistant":
|
|
35
|
+
# assistant 无 tool_calls -> 无 pending.
|
|
36
|
+
return []
|
|
37
|
+
return []
|
|
38
|
+
|
|
39
|
+
async def _save_checkpoint(self, ctx: AgentContext, graph: AgentGraph) -> None:
|
|
40
|
+
"""Auto-save checkpoint if store is configured."""
|
|
41
|
+
if not self.store:
|
|
42
|
+
return
|
|
43
|
+
try:
|
|
44
|
+
# 审计 P1-20/E-20: 捕获未闭合 tool_calls (assistant 发了 tool_calls 但
|
|
45
|
+
# resume 前无对应 tool 角色回复). 原仅存 messages, resume 从
|
|
46
|
+
# current_node_id 重跑会重发 tool_call 致重复副作用 (文件写两遍/命令
|
|
47
|
+
# 跑两次). 现显式记录, resume 据此标记跳过.
|
|
48
|
+
pending = self._extract_pending_tool_calls(ctx.messages)
|
|
49
|
+
self.store.save_checkpoint(
|
|
50
|
+
graph_id=graph.name,
|
|
51
|
+
session_id=ctx.session_id,
|
|
52
|
+
node_id=ctx.current_node_id or "",
|
|
53
|
+
state={
|
|
54
|
+
"messages": ctx.messages,
|
|
55
|
+
"iteration_count": ctx.iteration_count,
|
|
56
|
+
"variables": ctx.variables.to_dict(),
|
|
57
|
+
"tool_call_chain_count": ctx.tool_call_chain_count,
|
|
58
|
+
"pending_tool_calls": pending,
|
|
59
|
+
},
|
|
60
|
+
)
|
|
61
|
+
# #675: mirror the checkpoint into the kernel CheckpointStore
|
|
62
|
+
# (session-keyed, CheckpointState shape) for kernel-side
|
|
63
|
+
# resume/audit. Best-effort — save failures are logged inside.
|
|
64
|
+
kcp = getattr(self, "kernel_checkpoints", None)
|
|
65
|
+
if kcp is not None:
|
|
66
|
+
kcp.save(
|
|
67
|
+
ctx.session_id,
|
|
68
|
+
ctx.messages,
|
|
69
|
+
budget_spent_tokens=int(getattr(ctx, "tokens_used", 0) or 0),
|
|
70
|
+
permission_mode=str(getattr(ctx, "permission_mode", "") or ""),
|
|
71
|
+
metadata={
|
|
72
|
+
"graph_id": graph.name,
|
|
73
|
+
"node_id": ctx.current_node_id or "",
|
|
74
|
+
"iteration_count": ctx.iteration_count,
|
|
75
|
+
},
|
|
76
|
+
)
|
|
77
|
+
# #714 part 1: per-node state through the kernel-canonical
|
|
78
|
+
# binding API (fusion_harness.checkpoint_binding, harness K2
|
|
79
|
+
# #35) — same CheckpointStore, distinct "session:node" keys,
|
|
80
|
+
# so the old session-keyed rows stay byte-compatible. The
|
|
81
|
+
# node_effect_outbox (harness OutboxStore) is wired here for
|
|
82
|
+
# the binder; mark_emitted receipts for tool-call dedupe land
|
|
83
|
+
# with the tool-executor integration (follow-up, keeps this
|
|
84
|
+
# diff confined to the #714-listed files).
|
|
85
|
+
try:
|
|
86
|
+
from .paths import studio_home
|
|
87
|
+
|
|
88
|
+
outbox = getattr(self, "node_effect_outbox", None)
|
|
89
|
+
if outbox is None:
|
|
90
|
+
from fusion_harness.outbox import OutboxStore
|
|
91
|
+
|
|
92
|
+
outbox = OutboxStore(str(studio_home() / "node_effects.db"))
|
|
93
|
+
self.node_effect_outbox = outbox
|
|
94
|
+
from fusion_harness.checkpoint_binding import bind_node_state
|
|
95
|
+
|
|
96
|
+
binder = bind_node_state(kcp.store, outbox, ctx.session_id)
|
|
97
|
+
binder.save(
|
|
98
|
+
ctx.current_node_id or "run",
|
|
99
|
+
{
|
|
100
|
+
"graph_id": graph.name,
|
|
101
|
+
"iteration_count": ctx.iteration_count,
|
|
102
|
+
"variables": ctx.variables.to_dict(),
|
|
103
|
+
"pending_tool_calls": pending,
|
|
104
|
+
},
|
|
105
|
+
)
|
|
106
|
+
except Exception as bind_err:
|
|
107
|
+
logger.warning(
|
|
108
|
+
"node state binding failed session=%s: %s", ctx.session_id, bind_err
|
|
109
|
+
)
|
|
110
|
+
logger.debug(
|
|
111
|
+
"Checkpoint saved: graph=%s node=%s pending_tools=%d",
|
|
112
|
+
graph.name, ctx.current_node_id, len(pending),
|
|
113
|
+
)
|
|
114
|
+
ctx.checkpoint_fail_count = 0
|
|
115
|
+
# N8 #391: checkpoint hook trigger (auto-save path).
|
|
116
|
+
hooks = getattr(self, "hooks", None)
|
|
117
|
+
if hooks is not None:
|
|
118
|
+
try:
|
|
119
|
+
await hooks.fire(
|
|
120
|
+
"CHECKPOINT",
|
|
121
|
+
{
|
|
122
|
+
"graph": graph.name,
|
|
123
|
+
"session_id": ctx.session_id,
|
|
124
|
+
"node": ctx.current_node_id,
|
|
125
|
+
"pending_tool_calls": len(pending),
|
|
126
|
+
},
|
|
127
|
+
)
|
|
128
|
+
except Exception as hook_err:
|
|
129
|
+
logger.warning("checkpoint hook error: %s", hook_err)
|
|
130
|
+
except Exception as e:
|
|
131
|
+
ctx.checkpoint_fail_count += 1
|
|
132
|
+
# 审计 M-3: 持续失败 (DB 满/锁/schema 不匹配) 仅 warning 但执行照常,
|
|
133
|
+
# 之后 resume 报 "No checkpoint found" 用户无信号. 连续 3 次升级 error.
|
|
134
|
+
# 审计 P3-1: 计数迁 per-exec ctx, 并发执行各自累计不互踩.
|
|
135
|
+
if ctx.checkpoint_fail_count >= 3:
|
|
136
|
+
logger.error(
|
|
137
|
+
"Checkpoint save failed %d consecutive times (resume will not work): %s",
|
|
138
|
+
ctx.checkpoint_fail_count, e,
|
|
139
|
+
)
|
|
140
|
+
else:
|
|
141
|
+
logger.warning("Checkpoint save failed (%d): %s", ctx.checkpoint_fail_count, e)
|
|
142
|
+
|
|
143
|
+
async def resume_from_checkpoint(
|
|
144
|
+
self,
|
|
145
|
+
graph: AgentGraph,
|
|
146
|
+
session_id: str,
|
|
147
|
+
stream: bool = False,
|
|
148
|
+
human_inputs: dict | None = None,
|
|
149
|
+
) -> AsyncIterator[AgentEvent]:
|
|
150
|
+
"""Resume graph execution from the latest checkpoint."""
|
|
151
|
+
if not self.store:
|
|
152
|
+
yield AgentEvent(
|
|
153
|
+
type=AgentEventType.ERROR,
|
|
154
|
+
content="No store configured for checkpoint resume",
|
|
155
|
+
)
|
|
156
|
+
return
|
|
157
|
+
|
|
158
|
+
checkpoint = self.store.load_latest_checkpoint(graph_id=graph.name, session_id=session_id)
|
|
159
|
+
if not checkpoint:
|
|
160
|
+
yield AgentEvent(
|
|
161
|
+
type=AgentEventType.ERROR,
|
|
162
|
+
content=f"No checkpoint found for graph={graph.name} session={session_id}",
|
|
163
|
+
)
|
|
164
|
+
return
|
|
165
|
+
|
|
166
|
+
ctx = AgentContext(session_id=session_id)
|
|
167
|
+
# 审计 E-20: Checkpoint 是 dataclass 非 dict, 用属性 + 解析 state_json.
|
|
168
|
+
raw_state = checkpoint.context_json or "{}"
|
|
169
|
+
try:
|
|
170
|
+
state = json.loads(raw_state) if raw_state else {}
|
|
171
|
+
except (json.JSONDecodeError, TypeError):
|
|
172
|
+
state = {}
|
|
173
|
+
ctx.messages = state.get("messages", [])
|
|
174
|
+
ctx.iteration_count = state.get("iteration_count", 0)
|
|
175
|
+
ctx.current_node_id = checkpoint.current_node_id or graph.start_node_id
|
|
176
|
+
ctx.tool_call_chain_count = state.get("tool_call_chain_count", 0)
|
|
177
|
+
# 审计 P1-20/E-20: resume 检测 pending tool_calls, 标记 metadata 供
|
|
178
|
+
# tool 节点跳过重发 (避免重复副作用). 消息里 assistant tool_calls 已在,
|
|
179
|
+
# runtime 续跑时若 current_node_id 是被中断的 tool 节点会重发; 标记让
|
|
180
|
+
# 上层感知. 此处仅记日志 + 标记, 不自动删消息 (保留 LLM 上下文).
|
|
181
|
+
pending_tools = state.get("pending_tool_calls", [])
|
|
182
|
+
# #714 part 1: prefer the node-state binding (checkpoint_binding
|
|
183
|
+
# "session:node" key) when it holds fresher state for the checkpointed
|
|
184
|
+
# node than the legacy session row; old checkpoints without binding
|
|
185
|
+
# rows behave exactly as before.
|
|
186
|
+
kcp = getattr(self, "kernel_checkpoints", None)
|
|
187
|
+
bound_node_id = checkpoint.current_node_id or graph.start_node_id
|
|
188
|
+
if kcp is not None:
|
|
189
|
+
try:
|
|
190
|
+
from fusion_harness.checkpoint_binding import bind_node_state
|
|
191
|
+
|
|
192
|
+
from .paths import studio_home
|
|
193
|
+
|
|
194
|
+
outbox = getattr(self, "node_effect_outbox", None)
|
|
195
|
+
if outbox is None:
|
|
196
|
+
from fusion_harness.outbox import OutboxStore
|
|
197
|
+
|
|
198
|
+
outbox = OutboxStore(str(studio_home() / "node_effects.db"))
|
|
199
|
+
self.node_effect_outbox = outbox
|
|
200
|
+
binder = bind_node_state(kcp.store, outbox, session_id)
|
|
201
|
+
bound = binder.load(bound_node_id)
|
|
202
|
+
if isinstance(bound, dict):
|
|
203
|
+
if not ctx.messages and bound.get("pending_tool_calls"):
|
|
204
|
+
pending_tools = list(bound["pending_tool_calls"])
|
|
205
|
+
logger.info(
|
|
206
|
+
"node binding state loaded node=%s keys=%s",
|
|
207
|
+
bound_node_id,
|
|
208
|
+
sorted(bound),
|
|
209
|
+
)
|
|
210
|
+
except Exception as bind_err:
|
|
211
|
+
logger.warning("node binding load failed session=%s: %s", session_id, bind_err)
|
|
212
|
+
if pending_tools:
|
|
213
|
+
ctx.metadata["pending_tool_calls"] = pending_tools
|
|
214
|
+
logger.warning(
|
|
215
|
+
"Resumed with %d pending tool_calls (assistant issued but no tool "
|
|
216
|
+
"reply) — caller should skip re-dispatch to avoid duplicate side effects",
|
|
217
|
+
len(pending_tools),
|
|
218
|
+
)
|
|
219
|
+
# 审计 A-1 Tier3: resume 重建 per-exec variables (fresh VM + 载入快照),
|
|
220
|
+
# 不写回 singleton self.variables. dispatch 见 context 提供, 不 reseed.
|
|
221
|
+
ctx.variables = VariableManager()
|
|
222
|
+
|
|
223
|
+
saved_vars = state.get("variables", {})
|
|
224
|
+
for k, v in saved_vars.items():
|
|
225
|
+
ctx.variables.set(k, v)
|
|
226
|
+
|
|
227
|
+
# #557: decisions captured while the backend was down — inject as
|
|
228
|
+
# variables so the re-executed human_input node takes the resumed
|
|
229
|
+
# branch ({input_var: value} keys) instead of pausing again.
|
|
230
|
+
for k, v in (human_inputs or {}).items():
|
|
231
|
+
ctx.variables.set(k, v)
|
|
232
|
+
|
|
233
|
+
logger.info(
|
|
234
|
+
"Resumed from checkpoint: graph=%s node=%s iteration=%d pending=%d",
|
|
235
|
+
graph.name,
|
|
236
|
+
ctx.current_node_id,
|
|
237
|
+
ctx.iteration_count,
|
|
238
|
+
len(pending_tools),
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
yield AgentEvent(
|
|
242
|
+
type=AgentEventType.CHECKPOINT,
|
|
243
|
+
content=f"Resumed from checkpoint at node '{ctx.current_node_id}'",
|
|
244
|
+
metadata={"checkpoint": checkpoint.to_dict()},
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
exec_fn = self.execute_graph_stream if stream else self.execute_graph
|
|
248
|
+
async for event in exec_fn(graph, "", context=ctx):
|
|
249
|
+
yield event
|