Coverage for agentos/__init__.py: 100%
79 statements
« prev ^ index » next coverage.py v7.14.3, created at 2026-07-04 16:43 +0800
« prev ^ index » next coverage.py v7.14.3, created at 2026-07-04 16:43 +0800
1"""NexusAgent - Production-grade Agent Framework SDK
3__version__ = "1.16.46"
5v1.16.8: Seed Skill Ecosystem + P0 fix (version mismatch) — 64 skills generated, registered, marketplace-ready.
6v1.16.6: Core integration — AuditLogger + RateLimiter wired into AgentLoop.
7v1.16.5: P0 fixes — Feishu signature verification + AgentInfo class conflict resolved.
8v1.16.1: Core integration — CircuitBreaker, ToolOutputValidator, Metrics wired into ToolAgent + GraphExecutor.
9v1.16.0: 30 infrastructure tools (connection_pool, circuit_breaker, jwt, scheduler, etc.) consolidated release.
10v1.12.1: Async Parallel Primitives (fan-out/fan-in, parallel_gather, parallel_map, structured concurrency).
11v1.12.0: Letta-style Virtual Memory Pager (page-out/page-in + swap store + smart recall).
12v1.11.0: Background Task Manager + Agent Supervision Tree + Full Checkpoint Integration + Auto-Context Paging.
13v1.10.0: All-in — Deploy (Docker/K8s) + Eval (SWE-bench/GAIA) + Multimodal (Vision/Audio) + Prompt Hub (versioned) + Cost Tracker (pricing).
14v1.9.9: GuardPipeline (PII/Injection/Toxicity safety with strict/permissive modes).
15v1.9.5: CodeSandbox (safe code gen + test case validation) + Human-in-the-Loop breakpoints.
16v1.9.4: TaskDecomposer + ResultFusion + EvalFeedbackLoop (P0 three-bottleneck fix).
17v1.9.3: CompositeScorer V2 (BLEU smoothing + LLM-as-Judge), 50+ benchmark cases, 80% pass rate.
18v1.9.2: Swarm MESH 5x parallel acceleration, CompositeScorer (ROUGE-L+BLEU+contains+exact), 14 built-in benchmarks, AutoPilot self-healing.
19v1.7.1: System layer + Desktop client: visual approval engine (Agent applies → user clicks allow/deny), native desktop shell (pywebview wrapper), tiered file/shell/browser ops。
20v1.0.0: Production release — ToolUsingAgent CLI, Mock fallback mode,
21weather demo (`agentos demo`), unified LLM Provider abstraction,
22streaming/retry/checkpoint/resume, PyPI + TestPyPI dual publish.
24v1.3.38: +Tool-Using Agent streaming/retry/checkpoint/resume(run_stream/重试逻辑/断点恢复),
25+MockLLMProvider 集成测试支持。11+10 条 Agent 测试全过。
26v1.3.37: +Tool-Using Agent (agentos.agent) — 基于 LLM Function Calling 的自主 Agent 循环:
27ToolExecutor 工具注册/执行、多步推理闭环、同步/异步运行、成本追踪、端到端天气 Agent 示例。
28v1.3.36: +LLM Provider Module (agentos.llm) — unified abstraction with OpenAI/DeepSeek/Anthropic
29providers, Function Calling / Tool Use, streaming, cost estimation. 零 SDK 依赖 AnthropicProvider
30(pure httpx).
31v1.3.15: +SubAgent Parent-Child Communication (SharedState, ChildContext/ChildHandle, heartbeat,
32lifecycle management: pause/resume/cancel/timeout, heartbeat monitoring).
33v1.3.14: +OpenTelemetry Integration (otel_bridge: OtelConfig/OtelTracer/OtelMeter/OtelMiddleware).
34v1.3.13: +A2A Protocol v2 (Task Store with InMemory/SQLite backends, Streaming SSE task lifecycle
35notifications, enhanced A2AClient with retry/auth/connection pooling, A2AServer with FastAPI
36route builder + streaming + auth + pluggable persistence).
37v1.3.12: +Prompt Optimizer (DSPy-inspired iterative refinement, bootstrapping, multi-strategy),
38+Few-Shot Selector (similarity/diversity/label-balanced strategies),
39+SSE Streaming (ASGI SSE with heartbeats, backpressure, typed events).
40v1.3.11: +Guardrails (Input/Output safety engine with PII/Injection/Keyword/Toxicity rules, PolicyEnforcer),
41+HITL (Human-in-the-Loop approval workflows with RiskLevel auto-decision, caching, preset policies).
42v1.3.10: +Conversation Manager (multi-turn dialog, sliding window, branching, summarization).
43v1.3.9: +Schema Enforcer (Pydantic output validation/auto-repair).
44v1.3.8: +Quality (docstrings, bare-except/type-ignore fixes).
46v1.4.0: +End-to-end examples (multi_agent_research.py, file_ops_agent.py),
47+Professional README with feature comparison table,
48+CLI demo upgraded with self-check mode, +Agent marketplace listing.
49"""
51__version__ = "1.16.46"
53# v1.15.0: Tool Output Validation Layer (structured result validation + error classification + auto-repair suggestions).
54# v1.14.9: Memory Persistence Checkpoint Delivery - all 6 memory subsystems get_state()/restore_state() + ServerDaemon lifecycle integration + DaemonConfig + /api/daemon/memory endpoint.
55# v1.14.8: P0 regression fix (imports, version, dependencies).
57# Core - DI system
58from agentos.core.di import (
59 Agent,
60 RunContext,
61 Depends,
62 inject_tool,
63 requires_context,
64)
66# Core - Handoff protocol
67from agentos.core.handoff import (
68 Handoff,
69 HandoffResult,
70 transfer_to,
71 can_handle,
72 execute_with_handoff,
73 HandoffAwareAgent,
74)
76# Core - CodeAgent
77from agentos.core.code_agent import (
78 CodeAgent,
79 CodeResult,
80 CodeStep,
81)
83# Protocols - Structured output validation
84from agentos.protocols.output import (
85 StructuredOutput,
86 validate_output,
87 OutputValidator,
88)
90# Protocols - Agent Card
91from agentos.protocols.agent_card import (
92 AgentCard,
93 AgentCardRegistry,
94 AgentCardDiscovery,
95 discover_local,
96 create_card,
97)
99# Protocols - A2A
100from agentos.protocols.a2a import (
101 A2ATask,
102 A2AMessage,
103 A2AArtifact,
104 A2AHandoff,
105 A2ASession,
106 A2AClient,
107 A2AServer,
108 TextPart,
109 FilePart,
110 DataPart,
111 TaskState,
112 new_task,
113 new_handoff,
114)
116# Memory pyramid
117from agentos.memory.pyramid import (
118 MemoryPyramid,
119 MemoryLayer,
120 MemoryType,
121 MemoryItem,
122)
124# Evolution engine
125from agentos.evolution.engine import (
126 EvolutionEngine,
127 EvolutionProposal,
128 EvolutionStatus,
129)
131# Fusion toolkit
132from agentos.tools.fusion import (
133 FusionToolkit,
134 FusionResult,
135 ToolSpec,
136)
138# Tool risk rating (v1.1.4)
139from agentos.tools.risk import (
140 ToolRiskLevel,
141 ToolRiskRating,
142 get_risk_preset,
143 infer_risk_level,
144)
146# Swarm coordinator
147from agentos.swarm.coordinator import (
148 SwarmCoordinator,
149 SmartSwarmCoordinator,
150 SwarmTopology,
151 SwarmMessage,
152 ExecutionMode,
153 SwarmResult,
154)
156# Communication layer
157from agentos.comm.layer import (
158 CommunicationLayer,
159 Blackboard,
160 EventBus,
161 Mailbox,
162)
164# Orchestration
165from agentos.orchestration.graph import (
166 GraphOrchestrator,
167 GraphNode,
168 GraphEdge,
169)
171# Concurrency (v1.1.3)
172from agentos.concurrency.batch import (
173 AsyncBatchExecutor,
174 TaskStatus,
175 TaskSpec,
176 TaskResult,
177 BatchConfig,
178 BatchResult,
179 BatchStrategy,
180)
182# Cost tracking (v1.1.4)
183from agentos.cost.tracker import (
184 RunCostSession,
185 CostTracker,
186 ModelPricing,
187 UsageRecord,
188 PRICING,
189)
191# Models - Resilience (v1.1.5)
192from agentos.models.resilience import (
193 CancellationSource,
194 CancelledError,
195 RetryConfig,
196 CircuitBreaker,
197 CircuitBreakerConfig,
198 ResilienceConfig,
199 ResilientCall,
200 retry_with_backoff,
201 with_timeout,
202 with_fallback,
203)
205# Models - Router (v1.2.7 minimal)
206from agentos.models.router import ModelRouter
208from agentos.security.sandbox_executor import (
209 SandboxExecutor,
210 SandboxMode,
211 SandboxResult,
212 ProcessSandbox,
213 DockerSandbox,
214)
216# Core - Middleware Pipeline (v1.2.7)
217from agentos.core.middleware import (
218 MiddlewarePhase,
219 MiddlewareContext,
220 MiddlewareDecision,
221 AgentMiddleware,
222 MiddlewarePipeline,
223)
225# Queue - Task Queue & Rate Limiter (v1.2.7)
226from agentos.queue import (
227 TaskQueue,
228 TaskState,
229 TaskPriority,
230 RateLimiter,
231 RateLimitStrategy,
232 RateLimitConfig,
233)
235# Cache - LLM Response Cache (v1.2.7)
236from agentos.cache import (
237 LLMCache,
238 CacheEntry,
239 BaseEmbedder,
240 OpenAIEmbedder,
241 LocalEmbedder,
242 CohereEmbedder,
243 ResponseCache,
244 CacheKeyStrategy,
245)
247# Plugins - Plugin System (v1.2.7)
248from agentos.plugins import (
249 PluginRegistry,
250 RegisteredPlugin,
251 PluginStatus,
252 PluginDiscovery,
253 DiscoveredPlugin,
254 PluginLoader,
255 LifecycleManager,
256)
258# Observability (v1.2.7)
259from agentos.observability import (
260 MetricsCollector,
261 Tracer,
262 NoopTracer,
263 CostAnalytics,
264 BudgetAlert,
265)
267# Workflows (v1.2.7)
268from agentos.workflows import (
269 WorkflowEngine,
270 WorkflowTemplate,
271)
273# MCP Protocol (v1.2.7)
274from agentos.protocols.mcp import (
275 MCPClient,
276 MCPServerConfig,
277 MCPToolSchema,
278)
280# Config System (v1.2.7)
281from agentos.config import (
282 AgentOSConfig,
283 AgentOSPreset,
284 ValidationResult,
285)
287# Evaluation Framework (v1.3.18)
288from agentos.evaluation import (
289 GoldenDataset,
290 GoldenCase,
291 Evaluator,
292 EvalConfig,
293 EvalReport,
294 ScoreDetail,
295 Scorer,
296 load_dataset,
297 save_dataset,
298 quick_eval,
299)
301from agentos.evaluation.regression import (
302 RegressionRunner,
303 RegressionReport,
304 RegressionCheck,
305 StatisticalRunner,
306 StatResult,
307 to_junit_xml,
308 to_json,
309 save_report,
310)
312from agentos.evaluation.scorers import (
313 CompositeScorer,
314 ScoringStrategy,
315 ScoreResult,
316 rouge_l,
317 bleu,
318 semantic_similarity,
319 exact_match,
320 contains_match,
321 STRATEGY_CODE_GEN,
322 STRATEGY_QA,
323 STRATEGY_SUMMARY,
324 STRATEGY_TRANSLATION,
325)
327# Security - Auditor (v1.2.7)
328from agentos.security.auditor import (
329 SecurityAuditor,
330 AuditFinding,
331 AuditReport,
332)
334# Tools - Orchestrator (v1.2.7)
335from agentos.tools.orchestrator import (
336 ToolOrchestrator,
337 DAGBuilder,
338 DAGSpec,
339)
341# Memory - Retriever + Conversation (v1.2.7)
342from agentos.memory import (
343 SemanticMemoryRetriever,
344 ConversationMemory,
345)
347# Prompts (v1.2.7)
348from agentos.prompts import (
349 PromptTemplate,
350 PromptRegistry,
351)
353# Multimodal (v1.2.7)
354from agentos.multimodal import (
355 MultimodalManager,
356 Modality,
357)
359# Vector Store (v1.2.7)
360from agentos.vectorstore import (
361 BaseVectorStore,
362 FAISSVectorStore,
363 ChromaVectorStore,
364)
366# Errors (v1.2.8)
367from agentos.errors import (
368 ErrorCategory,
369 ErrorContext,
370 ErrorFormatter,
371 HumanError,
372)
374# Deployment (v1.2.8)
375from agentos.deployment import (
376 DockerConfig,
377 ComposeService,
378 ComposeConfig,
379)
381# Monitoring (v1.2.8)
382from agentos.monitoring import (
383 Alert,
384 AlertEvaluator,
385 AlertRule,
386 AlertSeverity,
387 AlertState,
388 MonitoringConfig,
389 WebhookConfig,
390 WebhookDispatcher,
391)
393# Experiments (v1.2.8)
394from agentos.experiments import (
395 ExperimentRunner,
396 ExperimentConfig,
397 ExperimentReport,
398 PromptVariant,
399 TrialResult,
400 Evaluator,
401)
403# Feedback (v1.2.8)
404from agentos.feedback import (
405 FeedbackCollector,
406 FeedbackRecord,
407 FeedbackType,
408 PreferenceLearner,
409)
411# Memory extensions (v1.2.8)
412from agentos.memory import (
413 MemorySummarizer,
414 ImportanceScorer,
415 MemoryChunk,
416 LongTermMemory,
417 MemoryStore,
418 WorkingMemory,
419 WorkingMemoryItem,
420 VectorMemory,
421)
423# Orchestration extensions (v1.2.8)
424from agentos.orchestration import (
425 A2ARouter,
426 RouterAgentCard,
427 RouterTask,
428 TaskResult,
429 TaskStatus,
430 AgentGraph,
431 GraphRecipe,
432 GraphNodeState,
433 GraphResult,
434)
436# Models - Routing Strategy (v1.2.8)
437from agentos.models.routing_strategy import (
438 RoutingStrategy,
439 Complexity,
440 Budget,
441)
443# Swarm Patterns (v1.2.8)
444from agentos.swarm import (
445 SwarmPatterns,
446 Topology,
447 CollaborationConfig,
448 CollaborationResult,
449)
451# Code Sandbox (v1.9.5)
452from agentos.swarm.code_sandbox import (
453 CodeSandbox,
454 SandboxResult,
455 TestCase,
456 CodeFeedbackExtractor,
457)
459# Human-in-the-Loop (v1.9.5)
460from agentos.swarm.human_loop import (
461 HITLManager,
462 HITLConfig,
463 Breakpoint,
464 BreakpointType,
465 HumanDecision,
466)
468# Core extensions (v1.2.9)
469from agentos.core import (
470 AgentContext,
471 ContextManager,
472 CoreMessage,
473 CoreToolCall,
474 CoreToolResult,
475 AgentStateMachine,
476 AgentState,
477 StateTransition,
478 TransitionError,
479 StateTimeoutError,
480 StreamChunk,
481 StreamEmitter,
482 StreamEvent,
483 ResponseCollector,
484 Session,
485 SessionStore,
486 AsyncAgentLoop,
487 AsyncLoopConfig,
488 AsyncInvocationResult,
489 AsyncContextManager,
490)
492# Logging (v1.2.9)
493from agentos.log import (
494 JSONFormatter,
495 TraceContext,
496)
498# Health (v1.2.9)
499from agentos.health import (
500 HealthChecker,
501 HealthStatus,
502 HealthCheck,
503 CheckResult,
504)
506# Security extensions (v1.9.9)
507from agentos.security import (
508 GuardPipeline,
509 InputGuard,
510 OutputGuard,
511 PIIDetector,
512 ContentSafetyFilter,
513 GuardChainResult,
514 GuardResult,
515 GuardAction,
516 Severity,
517 create_strict_guard,
518 create_permissive_guard,
519 SandboxManager,
520 Sandbox,
521 SafetyReport,
522 RiskLevel,
523 LLMSafetyAnalyzer,
524)
526# Storage (v1.2.9)
527from agentos.storage import (
528 CheckpointStore,
529 SqliteStore,
530)
532# Plugin Manager (v1.2.9)
533from agentos.plugin_manager import (
534 PluginManager,
535 PluginInfo,
536)
538# Cost - Token Counter (v1.2.9)
539from agentos.cost import (
540 TokenCounter,
541 TokenCount,
542 CostEstimate,
543 ModelFamily,
544)
546# Protocols - Contracts (v1.2.9)
547from agentos.protocols import (
548 AgentContract,
549 AgentCapability,
550 CapabilityDomain,
551 QoSLevel,
552 CapabilityMatcher,
553 ContractRegistry,
554 MatchScore,
555)
557# Memory - Compressor (v1.2.9)
558from agentos.memory import ContextCompressor
560# Tools extensions (v1.2.9)
561from agentos.tools import (
562 BaseTool,
563 PermissionLevel,
564 BaseToolCall,
565 BaseToolResult,
566 ToolRegistry,
567 ToolSchema,
568 FCToolCall,
569 FCToolResult,
570 FCToolRegistry,
571 OpenAPIToolGenerator,
572 GeneratedTool,
573)
575# SubAgent Manager (v1.2.9) + Parent-Child Communication (v1.3.15)
576from agentos.subagent import (
577 SubAgentManager,
578 SubAgentMode,
579 SubAgentSpec,
580 SubAgentResult,
581 ChildStatus,
582 ChildHeartbeat,
583 ChildInfo,
584 SharedState,
585 ChildContext,
586 ChildHandle,
587)
589# Agent Marketplace (v1.3.0)
590from agentos.agents.market import (
591 AgentMarket,
592 AgentSkill,
593 AgentCategory,
594)
596# Tool-Using Agent (v1.3.38)
597from agentos.agent import (
598 ToolAgent,
599 ToolExecutor,
600 AgentConfig,
601 AgentStep,
602 AgentResult,
603 MockLLMProvider,
604)
606# Agent Pipeline (v1.16.27)
607from agentos.agent.pipeline import (
608 PipelineAgent,
609 PipelineResult,
610 StepResult,
611 ConditionalPipeline,
612 ParallelPipeline,
613 RouterAgent,
614)
616# Core Runtime (v1.16.28)
617from agentos.core.async_loop import AsyncAgentLoop
619 # Built-in MCP Servers
621# A2A Router (v1.16.22)
622from agentos.orchestration.a2a_router import (
623 A2ARouter,
624 AgentCard,
625 Task,
626 TaskStatus,
627)
629from agentos.orchestration.task_decomposer import (
630 TaskDecomposer,
631 TaskNode,
632 TaskDAG,
633 DecompositionStrategy,
634)
636# LLM Provider Module (v1.3.36)
638# Prompt Optimizer (v1.3.12)
639from agentos.prompts.optimizer import (
640 PromptOptimizer,
641 OptimizerConfig,
642 OptimizationStrategy,
643 OptimizationResult,
644 PromptCandidate,
645)
647# Few-Shot Selector (v1.3.12)
648from agentos.prompts.few_shot import (
649 FewShotSelector,
650 Example,
651 SelectionStrategy,
652 build_examples,
653)
655# A2A Store (v1.3.13)
656from agentos.protocols.a2a_store import (
657 A2ATaskStore,
658 InMemoryTaskStore,
659 SqliteTaskStore,
660)
662# A2A Streaming (v1.3.13)
663from agentos.protocols.a2a_streaming import (
664 A2AStreamEvent,
665 TaskProgress,
666 A2AStreamSession,
667 A2AStreamManager,
668)
670# Distributed Orchestration (v1.16.14)
671from agentos.orchestration.distributed import (
672 DistSwarmCoordinator,
673 CrossNodeBus,
674 DistSwarmConfig,
675 CrossNodeMailbox,
676 DistTaskQueue,
677 DistTaskRecord,
678 DistTaskStatus,
679 DistAgentStatus,
680 PlacementStrategy,
681 AgentPlacementSpec,
682 quick_start,
683)
685# Parallel Orchestration (v1.16.15)
686from agentos.orchestration.parallel import (
687 ParallelExecutor,
688 TaskResult,
689 RunResult,
690 TaskStatus,
691)
693# LLM Cache (v1.16.17)
694from agentos.cache.llm_cache import (
695 LLMCache,
696 SemanticCache,
697 CacheEntry,
698 CacheStats,
699)
701# Response Cache + Embedder (v1.16.18)
702from agentos.cache.response_cache import (
703 ResponseCache,
704 CacheKeyStrategy,
705)
707from agentos.cache.embedder import (
708 OpenAIEmbedder,
709 LocalEmbedder,
710 CohereEmbedder,
711 EmbeddingResult,
712)
714# Multimodal Providers (v1.16.19)
715from agentos.multimodal.provider import (
716 MultiModalClient,
717 MultiModalContent,
718 MultiModalMessage,
719 OpenAIVisionProvider,
720 LocalVisionProvider,
721 OpenAIAudioProvider,
722 EdgeTTSProvider,
723)
725# Evaluation Suite (v1.16.20)
726from agentos.evaluation.suite import (
727 EvalSuiteRunner,
728 EvalScore,
729 HallucinationDetector,
730 Leaderboard,
731 LeaderboardEntry,
732 MultiRoundEvaluator,
733 SWEBenchEvaluator,
734)
736# Plugin Lifecycle & Registry (v1.16.21)
737from agentos.plugins.lifecycle import (
738 LifecycleManager,
739 LifecyclePlugin,
740 LifecycleReport,
741)
743from agentos.plugins.registry import (
744 PluginRegistry,
745 PluginManifest,
746 PluginType,
747 RegisteredPlugin,
748)
750# A2A Router (v1.16.22)
751from agentos.orchestration.a2a_router import (
752 A2ARouter,
753 AgentCard,
754 Task,
755 TaskStatus,
756)
758from agentos.orchestration.task_decomposer import (
759 TaskDecomposer,
760 TaskNode,
761 TaskDAG,
762 DecompositionStrategy,
763)