confused-ai-core 0.1.0
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.
- package/FEATURES.md +169 -0
- package/package.json +119 -0
- package/src/agent.ts +187 -0
- package/src/agentic/index.ts +87 -0
- package/src/agentic/runner.ts +386 -0
- package/src/agentic/types.ts +91 -0
- package/src/artifacts/artifact.ts +417 -0
- package/src/artifacts/index.ts +42 -0
- package/src/artifacts/media.ts +304 -0
- package/src/cli/index.ts +122 -0
- package/src/core/base-agent.ts +151 -0
- package/src/core/context-builder.ts +106 -0
- package/src/core/index.ts +8 -0
- package/src/core/schemas.ts +17 -0
- package/src/core/types.ts +158 -0
- package/src/create-agent.ts +309 -0
- package/src/debug-logger.ts +188 -0
- package/src/dx/agent.ts +88 -0
- package/src/dx/define-agent.ts +183 -0
- package/src/dx/dev-logger.ts +57 -0
- package/src/dx/index.ts +11 -0
- package/src/errors.ts +175 -0
- package/src/execution/engine.ts +522 -0
- package/src/execution/graph-builder.ts +362 -0
- package/src/execution/index.ts +8 -0
- package/src/execution/types.ts +257 -0
- package/src/execution/worker-pool.ts +308 -0
- package/src/extensions/index.ts +123 -0
- package/src/guardrails/allowlist.ts +155 -0
- package/src/guardrails/index.ts +17 -0
- package/src/guardrails/types.ts +159 -0
- package/src/guardrails/validator.ts +265 -0
- package/src/index.ts +74 -0
- package/src/knowledge/index.ts +5 -0
- package/src/knowledge/types.ts +52 -0
- package/src/learning/in-memory-store.ts +72 -0
- package/src/learning/index.ts +6 -0
- package/src/learning/types.ts +42 -0
- package/src/llm/cache.ts +300 -0
- package/src/llm/index.ts +22 -0
- package/src/llm/model-resolver.ts +81 -0
- package/src/llm/openai-provider.ts +313 -0
- package/src/llm/openrouter-provider.ts +29 -0
- package/src/llm/types.ts +131 -0
- package/src/memory/in-memory-store.ts +255 -0
- package/src/memory/index.ts +7 -0
- package/src/memory/types.ts +193 -0
- package/src/memory/vector-store.ts +251 -0
- package/src/observability/console-logger.ts +123 -0
- package/src/observability/index.ts +12 -0
- package/src/observability/metrics.ts +85 -0
- package/src/observability/otlp-exporter.ts +417 -0
- package/src/observability/tracer.ts +105 -0
- package/src/observability/types.ts +341 -0
- package/src/orchestration/agent-adapter.ts +33 -0
- package/src/orchestration/index.ts +34 -0
- package/src/orchestration/load-balancer.ts +151 -0
- package/src/orchestration/mcp-types.ts +59 -0
- package/src/orchestration/message-bus.ts +192 -0
- package/src/orchestration/orchestrator.ts +349 -0
- package/src/orchestration/pipeline.ts +66 -0
- package/src/orchestration/supervisor.ts +107 -0
- package/src/orchestration/swarm.ts +1099 -0
- package/src/orchestration/toolkit.ts +47 -0
- package/src/orchestration/types.ts +339 -0
- package/src/planner/classical-planner.ts +383 -0
- package/src/planner/index.ts +8 -0
- package/src/planner/llm-planner.ts +353 -0
- package/src/planner/types.ts +227 -0
- package/src/planner/validator.ts +297 -0
- package/src/production/circuit-breaker.ts +290 -0
- package/src/production/graceful-shutdown.ts +251 -0
- package/src/production/health.ts +333 -0
- package/src/production/index.ts +57 -0
- package/src/production/latency-eval.ts +62 -0
- package/src/production/rate-limiter.ts +287 -0
- package/src/production/resumable-stream.ts +289 -0
- package/src/production/types.ts +81 -0
- package/src/sdk/index.ts +374 -0
- package/src/session/db-driver.ts +50 -0
- package/src/session/in-memory-store.ts +235 -0
- package/src/session/index.ts +12 -0
- package/src/session/sql-store.ts +315 -0
- package/src/session/sqlite-store.ts +61 -0
- package/src/session/types.ts +153 -0
- package/src/tools/base-tool.ts +223 -0
- package/src/tools/browser-tool.ts +123 -0
- package/src/tools/calculator-tool.ts +265 -0
- package/src/tools/file-tools.ts +394 -0
- package/src/tools/github-tool.ts +432 -0
- package/src/tools/hackernews-tool.ts +187 -0
- package/src/tools/http-tool.ts +118 -0
- package/src/tools/index.ts +99 -0
- package/src/tools/jira-tool.ts +373 -0
- package/src/tools/notion-tool.ts +322 -0
- package/src/tools/openai-tool.ts +236 -0
- package/src/tools/registry.ts +131 -0
- package/src/tools/serpapi-tool.ts +234 -0
- package/src/tools/shell-tool.ts +118 -0
- package/src/tools/slack-tool.ts +327 -0
- package/src/tools/telegram-tool.ts +127 -0
- package/src/tools/types.ts +229 -0
- package/src/tools/websearch-tool.ts +335 -0
- package/src/tools/wikipedia-tool.ts +177 -0
- package/src/tools/yfinance-tool.ts +33 -0
- package/src/voice/index.ts +17 -0
- package/src/voice/voice-provider.ts +228 -0
- package/tests/artifact.test.ts +241 -0
- package/tests/circuit-breaker.test.ts +171 -0
- package/tests/health.test.ts +192 -0
- package/tests/llm-cache.test.ts +186 -0
- package/tests/rate-limiter.test.ts +161 -0
- package/tsconfig.json +29 -0
- package/vitest.config.ts +47 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supervisor pattern: a "boss" agent that delegates to specialist sub-agents
|
|
3
|
+
* and coordinates their results.
|
|
4
|
+
*
|
|
5
|
+
* Inspired by VoltAgent's supervisor pattern:
|
|
6
|
+
* https://github.com/VoltAgent/voltagent/blob/main/website/blog/2025-07-16-ai-agent-orchestration/index.md
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { Agent, AgentInput, AgentOutput, AgentContext } from '../core/types.js';
|
|
10
|
+
import { AgentState } from '../core/types.js';
|
|
11
|
+
import type { AgentRole } from './types.js';
|
|
12
|
+
import { CoordinationType } from './types.js';
|
|
13
|
+
import { OrchestratorImpl } from './orchestrator.js';
|
|
14
|
+
import { createRunnableAgent } from './agent-adapter.js';
|
|
15
|
+
|
|
16
|
+
export interface SupervisorConfig {
|
|
17
|
+
readonly name: string;
|
|
18
|
+
readonly description?: string;
|
|
19
|
+
/** Sub-agents with their roles (each agent will be registered with the orchestrator) */
|
|
20
|
+
readonly subAgents: Array<{ agent: Agent; role: AgentRole }>;
|
|
21
|
+
/** Optional guidelines for the supervisor (e.g. "Always assign the right task to the right agent") */
|
|
22
|
+
readonly guidelines?: string[];
|
|
23
|
+
/** Coordination strategy: SEQUENTIAL (default) or PARALLEL */
|
|
24
|
+
readonly coordinationType?: CoordinationType;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Creates a supervisor agent that coordinates multiple specialist agents.
|
|
29
|
+
* When run, it delegates the task to all sub-agents (in sequence or parallel)
|
|
30
|
+
* and combines their results.
|
|
31
|
+
*/
|
|
32
|
+
export function createSupervisor(config: SupervisorConfig): Agent {
|
|
33
|
+
const orchestrator = new OrchestratorImpl();
|
|
34
|
+
const coordinationType = config.coordinationType ?? 'sequential' as CoordinationType;
|
|
35
|
+
|
|
36
|
+
for (const { agent, role } of config.subAgents) {
|
|
37
|
+
orchestrator.registerAgent(agent, role);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const run = async (input: AgentInput, _ctx: AgentContext): Promise<AgentOutput> => {
|
|
41
|
+
await orchestrator.start();
|
|
42
|
+
|
|
43
|
+
const agents = orchestrator.listAgents();
|
|
44
|
+
const taskId = `task-${Date.now()}`;
|
|
45
|
+
|
|
46
|
+
const result = await orchestrator.coordinate(agents, {
|
|
47
|
+
id: taskId,
|
|
48
|
+
description: input.prompt,
|
|
49
|
+
subtasks: [],
|
|
50
|
+
coordinationType:
|
|
51
|
+
coordinationType === 'parallel' ? CoordinationType.PARALLEL : CoordinationType.SEQUENTIAL,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
await orchestrator.stop();
|
|
55
|
+
|
|
56
|
+
const outputs: Record<string, unknown> = {};
|
|
57
|
+
result.results.forEach((output, agentId) => {
|
|
58
|
+
outputs[agentId] = output.result;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
result: {
|
|
63
|
+
combined: outputs,
|
|
64
|
+
status: result.status,
|
|
65
|
+
executionTimeMs: result.executionTimeMs,
|
|
66
|
+
guidelines: config.guidelines,
|
|
67
|
+
},
|
|
68
|
+
state: result.status === 'success' ? AgentState.COMPLETED : AgentState.FAILED,
|
|
69
|
+
metadata: {
|
|
70
|
+
startTime: new Date(Date.now() - result.executionTimeMs),
|
|
71
|
+
durationMs: result.executionTimeMs,
|
|
72
|
+
iterations: agents.length,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
return createRunnableAgent({
|
|
78
|
+
name: config.name,
|
|
79
|
+
description: config.description ?? `Supervisor coordinating ${config.subAgents.length} agents`,
|
|
80
|
+
run,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Create a default AgentRole for a specialist agent
|
|
86
|
+
*/
|
|
87
|
+
export function createRole(
|
|
88
|
+
name: string,
|
|
89
|
+
responsibilities: string[],
|
|
90
|
+
options?: { description?: string; canExecuteTools?: boolean }
|
|
91
|
+
): AgentRole {
|
|
92
|
+
const id = `role-${name.toLowerCase().replace(/\s+/g, '-')}-${Date.now()}`;
|
|
93
|
+
return {
|
|
94
|
+
id,
|
|
95
|
+
name,
|
|
96
|
+
description: options?.description ?? `${name} specialist`,
|
|
97
|
+
responsibilities,
|
|
98
|
+
permissions: {
|
|
99
|
+
canExecuteTools: options?.canExecuteTools ?? true,
|
|
100
|
+
canAccessMemory: true,
|
|
101
|
+
canCreateSubAgents: false,
|
|
102
|
+
canModifyPlan: false,
|
|
103
|
+
},
|
|
104
|
+
canDelegate: false,
|
|
105
|
+
canCommunicateWith: [],
|
|
106
|
+
};
|
|
107
|
+
}
|