@serverless-dna/sop-agents 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/LICENSE +21 -0
- package/README.md +145 -0
- package/dist/agent-discovery.d.ts +21 -0
- package/dist/agent-discovery.d.ts.map +1 -0
- package/dist/agent-discovery.js +97 -0
- package/dist/agent-discovery.js.map +1 -0
- package/dist/agents/discovery.d.ts +21 -0
- package/dist/agents/discovery.d.ts.map +1 -0
- package/dist/agents/discovery.js +97 -0
- package/dist/agents/discovery.js.map +1 -0
- package/dist/agents/sop-loader.d.ts +20 -0
- package/dist/agents/sop-loader.d.ts.map +1 -0
- package/dist/agents/sop-loader.js +150 -0
- package/dist/agents/sop-loader.js.map +1 -0
- package/dist/agents/tool-generator.d.ts +66 -0
- package/dist/agents/tool-generator.d.ts.map +1 -0
- package/dist/agents/tool-generator.js +171 -0
- package/dist/agents/tool-generator.js.map +1 -0
- package/dist/default-orchestrator.d.ts +7 -0
- package/dist/default-orchestrator.d.ts.map +1 -0
- package/dist/default-orchestrator.js +50 -0
- package/dist/default-orchestrator.js.map +1 -0
- package/dist/errors.d.ts +51 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +80 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +26 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +89 -0
- package/dist/logger.js.map +1 -0
- package/dist/model-factory.d.ts +36 -0
- package/dist/model-factory.d.ts.map +1 -0
- package/dist/model-factory.js +55 -0
- package/dist/model-factory.js.map +1 -0
- package/dist/orchestrator/default-orchestrator.d.ts +7 -0
- package/dist/orchestrator/default-orchestrator.d.ts.map +1 -0
- package/dist/orchestrator/default-orchestrator.js +50 -0
- package/dist/orchestrator/default-orchestrator.js.map +1 -0
- package/dist/orchestrator/orchestrator.d.ts +47 -0
- package/dist/orchestrator/orchestrator.d.ts.map +1 -0
- package/dist/orchestrator/orchestrator.js +276 -0
- package/dist/orchestrator/orchestrator.js.map +1 -0
- package/dist/orchestrator.d.ts +50 -0
- package/dist/orchestrator.d.ts.map +1 -0
- package/dist/orchestrator.js +281 -0
- package/dist/orchestrator.js.map +1 -0
- package/dist/sop-loader.d.ts +20 -0
- package/dist/sop-loader.d.ts.map +1 -0
- package/dist/sop-loader.js +150 -0
- package/dist/sop-loader.js.map +1 -0
- package/dist/tool-generator.d.ts +66 -0
- package/dist/tool-generator.d.ts.map +1 -0
- package/dist/tool-generator.js +171 -0
- package/dist/tool-generator.js.map +1 -0
- package/dist/types/errors.d.ts +51 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +80 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/types.d.ts +160 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +2 -0
- package/dist/types/types.js.map +1 -0
- package/dist/types.d.ts +157 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Model } from "@strands-agents/sdk";
|
|
2
|
+
/**
|
|
3
|
+
* Supported model providers
|
|
4
|
+
*/
|
|
5
|
+
export type ModelProvider = "bedrock" | "openai";
|
|
6
|
+
/**
|
|
7
|
+
* Parsed model specification
|
|
8
|
+
*/
|
|
9
|
+
export interface ParsedModelSpec {
|
|
10
|
+
provider: ModelProvider;
|
|
11
|
+
modelId: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Parse a model specification string into provider and model ID.
|
|
15
|
+
* Format: "<provider>/<modelId>" or just "<modelId>" (defaults to bedrock)
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* parseModelSpec("bedrock/us.anthropic.claude-sonnet-4-20250514-v1:0")
|
|
19
|
+
* // => { provider: "bedrock", modelId: "us.anthropic.claude-sonnet-4-20250514-v1:0" }
|
|
20
|
+
*
|
|
21
|
+
* parseModelSpec("openai/gpt-4o")
|
|
22
|
+
* // => { provider: "openai", modelId: "gpt-4o" }
|
|
23
|
+
*
|
|
24
|
+
* parseModelSpec("us.anthropic.claude-sonnet-4-20250514-v1:0")
|
|
25
|
+
* // => { provider: "bedrock", modelId: "us.anthropic.claude-sonnet-4-20250514-v1:0" }
|
|
26
|
+
*/
|
|
27
|
+
export declare function parseModelSpec(modelSpec: string, defaultProvider?: ModelProvider): ParsedModelSpec;
|
|
28
|
+
/**
|
|
29
|
+
* Create a Model instance from a parsed model specification
|
|
30
|
+
*/
|
|
31
|
+
export declare function createModel(spec: ParsedModelSpec): Model;
|
|
32
|
+
/**
|
|
33
|
+
* Create a Model instance from a model specification string
|
|
34
|
+
*/
|
|
35
|
+
export declare function createModelFromSpec(modelSpec: string, defaultProvider?: ModelProvider): Model;
|
|
36
|
+
//# sourceMappingURL=model-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-factory.d.ts","sourceRoot":"","sources":["../src/model-factory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAGjD;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,QAAQ,EAAE,aAAa,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAC7B,SAAS,EAAE,MAAM,EACjB,eAAe,GAAE,aAAyB,GACxC,eAAe,CAkBjB;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,eAAe,GAAG,KAAK,CAaxD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAClC,SAAS,EAAE,MAAM,EACjB,eAAe,GAAE,aAAyB,GACxC,KAAK,CAGP"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { BedrockModel } from "@strands-agents/sdk/bedrock";
|
|
2
|
+
/**
|
|
3
|
+
* Parse a model specification string into provider and model ID.
|
|
4
|
+
* Format: "<provider>/<modelId>" or just "<modelId>" (defaults to bedrock)
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* parseModelSpec("bedrock/us.anthropic.claude-sonnet-4-20250514-v1:0")
|
|
8
|
+
* // => { provider: "bedrock", modelId: "us.anthropic.claude-sonnet-4-20250514-v1:0" }
|
|
9
|
+
*
|
|
10
|
+
* parseModelSpec("openai/gpt-4o")
|
|
11
|
+
* // => { provider: "openai", modelId: "gpt-4o" }
|
|
12
|
+
*
|
|
13
|
+
* parseModelSpec("us.anthropic.claude-sonnet-4-20250514-v1:0")
|
|
14
|
+
* // => { provider: "bedrock", modelId: "us.anthropic.claude-sonnet-4-20250514-v1:0" }
|
|
15
|
+
*/
|
|
16
|
+
export function parseModelSpec(modelSpec, defaultProvider = "bedrock") {
|
|
17
|
+
const slashIndex = modelSpec.indexOf("/");
|
|
18
|
+
if (slashIndex === -1) {
|
|
19
|
+
// No provider prefix, use default
|
|
20
|
+
return { provider: defaultProvider, modelId: modelSpec };
|
|
21
|
+
}
|
|
22
|
+
const providerPart = modelSpec.substring(0, slashIndex).toLowerCase();
|
|
23
|
+
const modelId = modelSpec.substring(slashIndex + 1);
|
|
24
|
+
// Validate provider
|
|
25
|
+
if (providerPart === "bedrock" || providerPart === "openai") {
|
|
26
|
+
return { provider: providerPart, modelId };
|
|
27
|
+
}
|
|
28
|
+
// Unknown provider prefix - treat the whole thing as a model ID
|
|
29
|
+
return { provider: defaultProvider, modelId: modelSpec };
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Create a Model instance from a parsed model specification
|
|
33
|
+
*/
|
|
34
|
+
export function createModel(spec) {
|
|
35
|
+
switch (spec.provider) {
|
|
36
|
+
case "bedrock":
|
|
37
|
+
return new BedrockModel({ modelId: spec.modelId });
|
|
38
|
+
case "openai": {
|
|
39
|
+
// Dynamic import to avoid requiring openai package when not used
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
41
|
+
const { OpenAIModel } = require("@strands-agents/sdk/openai");
|
|
42
|
+
return new OpenAIModel({ modelId: spec.modelId });
|
|
43
|
+
}
|
|
44
|
+
default:
|
|
45
|
+
throw new Error(`Unsupported model provider: ${spec.provider}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Create a Model instance from a model specification string
|
|
50
|
+
*/
|
|
51
|
+
export function createModelFromSpec(modelSpec, defaultProvider = "bedrock") {
|
|
52
|
+
const parsed = parseModelSpec(modelSpec, defaultProvider);
|
|
53
|
+
return createModel(parsed);
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=model-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-factory.js","sourceRoot":"","sources":["../src/model-factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAe3D;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,cAAc,CAC7B,SAAiB,EACjB,kBAAiC,SAAS;IAE1C,MAAM,UAAU,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAE1C,IAAI,UAAU,KAAK,CAAC,CAAC,EAAE,CAAC;QACvB,kCAAkC;QAClC,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;IAC1D,CAAC;IAED,MAAM,YAAY,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,WAAW,EAAE,CAAC;IACtE,MAAM,OAAO,GAAG,SAAS,CAAC,SAAS,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;IAEpD,oBAAoB;IACpB,IAAI,YAAY,KAAK,SAAS,IAAI,YAAY,KAAK,QAAQ,EAAE,CAAC;QAC7D,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC;IAC5C,CAAC;IAED,gEAAgE;IAChE,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AAC1D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,IAAqB;IAChD,QAAQ,IAAI,CAAC,QAAQ,EAAE,CAAC;QACvB,KAAK,SAAS;YACb,OAAO,IAAI,YAAY,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QACpD,KAAK,QAAQ,CAAC,CAAC,CAAC;YACf,iEAAiE;YACjE,iEAAiE;YACjE,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;YAC9D,OAAO,IAAI,WAAW,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QACnD,CAAC;QACD;YACC,MAAM,IAAI,KAAK,CAAC,+BAA+B,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;IAClE,CAAC;AACF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAClC,SAAiB,EACjB,kBAAiC,SAAS;IAE1C,MAAM,MAAM,GAAG,cAAc,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;IAC1D,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SOPDefinition } from "../types/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Default orchestrator SOP that ships with the package.
|
|
4
|
+
* Used when no orchestrator.md is found in the user's SOP directory.
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEFAULT_ORCHESTRATOR: SOPDefinition;
|
|
7
|
+
//# sourceMappingURL=default-orchestrator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-orchestrator.d.ts","sourceRoot":"","sources":["../../src/orchestrator/default-orchestrator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,aA2ClC,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Default orchestrator SOP that ships with the package.
|
|
4
|
+
* Used when no orchestrator.md is found in the user's SOP directory.
|
|
5
|
+
*/
|
|
6
|
+
export const DEFAULT_ORCHESTRATOR = {
|
|
7
|
+
name: "orchestrator",
|
|
8
|
+
description: "Master orchestrator that delegates tasks to specialized agents",
|
|
9
|
+
version: "1.0.0",
|
|
10
|
+
type: "orchestrator",
|
|
11
|
+
tools: [],
|
|
12
|
+
inputs: {},
|
|
13
|
+
filepath: "<built-in>",
|
|
14
|
+
zodSchema: z.object({ task: z.string().describe("The task to perform") }),
|
|
15
|
+
body: `# Task Orchestrator
|
|
16
|
+
|
|
17
|
+
## Overview
|
|
18
|
+
|
|
19
|
+
You are a master orchestrator responsible for coordinating multiple specialized agents to complete complex tasks.
|
|
20
|
+
|
|
21
|
+
## Steps
|
|
22
|
+
|
|
23
|
+
### 1. Analyze Request
|
|
24
|
+
|
|
25
|
+
Parse the incoming request to understand what needs to be accomplished.
|
|
26
|
+
|
|
27
|
+
**Constraints:**
|
|
28
|
+
- You MUST identify all subtasks required to fulfill the request
|
|
29
|
+
- You SHOULD break complex requests into smaller, manageable tasks
|
|
30
|
+
|
|
31
|
+
### 2. Delegate to Agents
|
|
32
|
+
|
|
33
|
+
Invoke the appropriate specialized agents for each subtask.
|
|
34
|
+
|
|
35
|
+
**Constraints:**
|
|
36
|
+
- You MUST choose the most appropriate agent for each subtask
|
|
37
|
+
- You MUST pass relevant context between agent calls
|
|
38
|
+
- You SHOULD handle agent errors gracefully
|
|
39
|
+
- You MUST ask the user for more detail if you do not have sufficient inputs for agent execution
|
|
40
|
+
|
|
41
|
+
### 3. Synthesize Results
|
|
42
|
+
|
|
43
|
+
Combine outputs from all agents into a coherent response.
|
|
44
|
+
|
|
45
|
+
**Constraints:**
|
|
46
|
+
- You MUST include the actual content produced by agents (poems, jokes, stories, etc.) in your response because the user wants to see the content, not just a description of it
|
|
47
|
+
- You MUST provide a unified response that addresses the original request
|
|
48
|
+
- You MAY add brief context before or after the agent's output`,
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=default-orchestrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-orchestrator.js","sourceRoot":"","sources":["../../src/orchestrator/default-orchestrator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAkB;IAClD,IAAI,EAAE,cAAc;IACpB,WAAW,EAAE,gEAAgE;IAC7E,OAAO,EAAE,OAAO;IAChB,IAAI,EAAE,cAAc;IACpB,KAAK,EAAE,EAAE;IACT,MAAM,EAAE,EAAE;IACV,QAAQ,EAAE,YAAY;IACtB,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,qBAAqB,CAAC,EAAE,CAAC;IACzE,IAAI,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+DAiCwD;CAC9D,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { InvokeOptions, InvokeResult, Orchestrator, OrchestratorConfig, OrchestratorStreamEvent, SOPDefinition } from "../types/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* OrchestratorImpl class implementing the Orchestrator interface
|
|
4
|
+
*/
|
|
5
|
+
export declare class OrchestratorImpl implements Orchestrator {
|
|
6
|
+
private readonly _config;
|
|
7
|
+
private registry;
|
|
8
|
+
private orchestratorAgent;
|
|
9
|
+
private orchestratorSOP;
|
|
10
|
+
private logger;
|
|
11
|
+
private currentCorrelationId?;
|
|
12
|
+
constructor(config?: OrchestratorConfig);
|
|
13
|
+
/**
|
|
14
|
+
* Current configuration (readonly for inspection)
|
|
15
|
+
*/
|
|
16
|
+
get config(): OrchestratorConfig;
|
|
17
|
+
/**
|
|
18
|
+
* Initialize the orchestrator by discovering agents and creating tools
|
|
19
|
+
*/
|
|
20
|
+
initialize(): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Process a request through the orchestrator agent
|
|
23
|
+
*/
|
|
24
|
+
invoke(request: string): Promise<string>;
|
|
25
|
+
invoke(request: string, options: InvokeOptions): Promise<InvokeResult>;
|
|
26
|
+
/**
|
|
27
|
+
* Stream events from the orchestrator in real-time
|
|
28
|
+
*/
|
|
29
|
+
stream(request: string): AsyncGenerator<OrchestratorStreamEvent>;
|
|
30
|
+
/**
|
|
31
|
+
* Clear agent cache
|
|
32
|
+
*/
|
|
33
|
+
clearCache(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Get the agent registry (for inspection/debugging)
|
|
36
|
+
*/
|
|
37
|
+
getRegistry(): Map<string, SOPDefinition>;
|
|
38
|
+
/**
|
|
39
|
+
* Wrap tools with error handling and logging
|
|
40
|
+
*/
|
|
41
|
+
private wrapToolsWithErrorHandling;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Factory function to create and initialize an orchestrator
|
|
45
|
+
*/
|
|
46
|
+
export declare function createOrchestrator(config?: OrchestratorConfig): Promise<Orchestrator>;
|
|
47
|
+
//# sourceMappingURL=orchestrator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../../src/orchestrator/orchestrator.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAEX,aAAa,EACb,YAAY,EAGZ,YAAY,EACZ,kBAAkB,EAClB,uBAAuB,EACvB,aAAa,EACb,MAAM,mBAAmB,CAAC;AAqB3B;;GAEG;AACH,qBAAa,gBAAiB,YAAW,YAAY;IACpD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6B;IACrD,OAAO,CAAC,QAAQ,CAAyC;IACzD,OAAO,CAAC,iBAAiB,CAAsB;IAC/C,OAAO,CAAC,eAAe,CAA8B;IACrD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,oBAAoB,CAAC,CAAS;gBAE1B,MAAM,GAAE,kBAAuB;IAmB3C;;OAEG;IACH,IAAI,MAAM,IAAI,kBAAkB,CAE/B;IAED;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAoCjC;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IACxC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;IA0GtE;;OAEG;IACI,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,CAAC,uBAAuB,CAAC;IAiCvE;;OAEG;IACH,UAAU,IAAI,IAAI;IAIlB;;OAEG;IACH,WAAW,IAAI,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC;IAIzC;;OAEG;IACH,OAAO,CAAC,0BAA0B;CAwGlC;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACvC,MAAM,GAAE,kBAAuB,GAC7B,OAAO,CAAC,YAAY,CAAC,CAIvB"}
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { Agent as StrandsAgent } from "@strands-agents/sdk";
|
|
2
|
+
import { discoverAgents, findOrchestrator } from "../agents/discovery.js";
|
|
3
|
+
import { clearCache as clearToolCache, createAllTools, getOrCreateAgent, setDefaultModelSpec, setDefaultProvider, setPrinterEnabled, } from "../agents/tool-generator.js";
|
|
4
|
+
import { LoggerImpl } from "../logger.js";
|
|
5
|
+
import { createModelFromSpec } from "../model-factory.js";
|
|
6
|
+
import { AgentInvocationError } from "../types/errors.js";
|
|
7
|
+
/**
|
|
8
|
+
* Generate a unique correlation ID for request tracing
|
|
9
|
+
*/
|
|
10
|
+
function generateCorrelationId() {
|
|
11
|
+
return `req-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* OrchestratorImpl class implementing the Orchestrator interface
|
|
15
|
+
*/
|
|
16
|
+
export class OrchestratorImpl {
|
|
17
|
+
_config;
|
|
18
|
+
registry = new Map();
|
|
19
|
+
orchestratorAgent = null;
|
|
20
|
+
orchestratorSOP = null;
|
|
21
|
+
logger;
|
|
22
|
+
currentCorrelationId;
|
|
23
|
+
constructor(config = {}) {
|
|
24
|
+
this._config = {
|
|
25
|
+
directory: config.directory ?? "./sops",
|
|
26
|
+
errorMode: config.errorMode ?? "fail-fast",
|
|
27
|
+
logLevel: config.logLevel ?? "info",
|
|
28
|
+
defaultModel: config.defaultModel,
|
|
29
|
+
defaultProvider: config.defaultProvider ?? "bedrock",
|
|
30
|
+
showThinking: config.showThinking ?? false,
|
|
31
|
+
};
|
|
32
|
+
this.logger = new LoggerImpl(this._config.logLevel);
|
|
33
|
+
// Set the default model and provider for tool-generator
|
|
34
|
+
setDefaultModelSpec(this._config.defaultModel);
|
|
35
|
+
setDefaultProvider(this._config.defaultProvider);
|
|
36
|
+
// Only print agent output to console in debug mode
|
|
37
|
+
setPrinterEnabled(this._config.logLevel === "debug");
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Current configuration (readonly for inspection)
|
|
41
|
+
*/
|
|
42
|
+
get config() {
|
|
43
|
+
return { ...this._config };
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Initialize the orchestrator by discovering agents and creating tools
|
|
47
|
+
*/
|
|
48
|
+
async initialize() {
|
|
49
|
+
const directory = this._config.directory ?? "./sops";
|
|
50
|
+
// Discover agents
|
|
51
|
+
this.registry = await discoverAgents(directory);
|
|
52
|
+
// Find orchestrator SOP
|
|
53
|
+
this.orchestratorSOP = await findOrchestrator(directory);
|
|
54
|
+
// Create tools for all agents
|
|
55
|
+
const tools = createAllTools(this.registry);
|
|
56
|
+
// Wrap tools with error handling and logging
|
|
57
|
+
const wrappedTools = this.wrapToolsWithErrorHandling(tools);
|
|
58
|
+
// Determine model for orchestrator (SOP-specific, config default, or Strands default)
|
|
59
|
+
const orchestratorModelSpec = this.orchestratorSOP.model ?? this._config.defaultModel;
|
|
60
|
+
// Create orchestrator agent with SOP body as system prompt
|
|
61
|
+
const agentConfig = {
|
|
62
|
+
systemPrompt: this.orchestratorSOP.body,
|
|
63
|
+
tools: wrappedTools,
|
|
64
|
+
printer: this._config.logLevel === "debug",
|
|
65
|
+
};
|
|
66
|
+
if (orchestratorModelSpec) {
|
|
67
|
+
agentConfig.model = createModelFromSpec(orchestratorModelSpec, this._config.defaultProvider);
|
|
68
|
+
}
|
|
69
|
+
this.orchestratorAgent = new StrandsAgent(agentConfig);
|
|
70
|
+
}
|
|
71
|
+
async invoke(request, options) {
|
|
72
|
+
if (!this.orchestratorAgent) {
|
|
73
|
+
throw new Error("Orchestrator not initialized. Call initialize() first.");
|
|
74
|
+
}
|
|
75
|
+
const showThinking = options?.showThinking ?? this._config.showThinking;
|
|
76
|
+
// Generate correlation ID for request and store it for tool access
|
|
77
|
+
const correlationId = generateCorrelationId();
|
|
78
|
+
this.currentCorrelationId = correlationId;
|
|
79
|
+
const requestLogger = this.logger.withCorrelationId(correlationId);
|
|
80
|
+
// Log request start
|
|
81
|
+
requestLogger.info(`Processing request: ${request.substring(0, 100)}...`, {
|
|
82
|
+
requestLength: request.length,
|
|
83
|
+
});
|
|
84
|
+
const startTime = Date.now();
|
|
85
|
+
const thinking = [];
|
|
86
|
+
const toolCalls = [];
|
|
87
|
+
let responseText = "";
|
|
88
|
+
try {
|
|
89
|
+
// Use streaming to capture thinking and tool calls
|
|
90
|
+
for await (const event of this.orchestratorAgent.stream(request)) {
|
|
91
|
+
// Capture thinking/reasoning content
|
|
92
|
+
if (event.type === "modelContentBlockDeltaEvent" &&
|
|
93
|
+
// biome-ignore lint/suspicious/noExplicitAny: SDK event types vary
|
|
94
|
+
event.delta?.type === "thinkingDelta") {
|
|
95
|
+
// biome-ignore lint/suspicious/noExplicitAny: SDK event types vary
|
|
96
|
+
const thinkingText = event.delta?.thinking;
|
|
97
|
+
if (thinkingText && showThinking) {
|
|
98
|
+
thinking.push(thinkingText);
|
|
99
|
+
requestLogger.debug(`Thinking: ${thinkingText.substring(0, 100)}...`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Capture text content
|
|
103
|
+
if (event.type === "modelContentBlockDeltaEvent" &&
|
|
104
|
+
// biome-ignore lint/suspicious/noExplicitAny: SDK event types vary
|
|
105
|
+
event.delta?.type === "textDelta") {
|
|
106
|
+
// biome-ignore lint/suspicious/noExplicitAny: SDK event types vary
|
|
107
|
+
responseText += event.delta?.text ?? "";
|
|
108
|
+
}
|
|
109
|
+
// Capture tool use starts
|
|
110
|
+
if (event.type === "modelContentBlockStartEvent" &&
|
|
111
|
+
// biome-ignore lint/suspicious/noExplicitAny: SDK event types vary
|
|
112
|
+
event.start?.type === "toolUseStart") {
|
|
113
|
+
// biome-ignore lint/suspicious/noExplicitAny: SDK event types vary
|
|
114
|
+
const toolName = event.start?.name;
|
|
115
|
+
if (toolName) {
|
|
116
|
+
requestLogger.debug(`Tool selected: ${toolName}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// Capture tool calls from beforeToolsEvent
|
|
120
|
+
if (event.type === "beforeToolsEvent") {
|
|
121
|
+
// biome-ignore lint/suspicious/noExplicitAny: SDK event types vary
|
|
122
|
+
const toolUses = event.toolUses;
|
|
123
|
+
if (Array.isArray(toolUses)) {
|
|
124
|
+
for (const toolUse of toolUses) {
|
|
125
|
+
toolCalls.push({
|
|
126
|
+
name: toolUse.name,
|
|
127
|
+
input: toolUse.input,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const duration = Date.now() - startTime;
|
|
134
|
+
requestLogger.info(`Request completed in ${duration}ms`);
|
|
135
|
+
// Return string if no options, InvokeResult if options provided
|
|
136
|
+
if (options) {
|
|
137
|
+
return {
|
|
138
|
+
response: responseText,
|
|
139
|
+
thinking: thinking.length > 0 ? thinking : undefined,
|
|
140
|
+
toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return responseText;
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
const duration = Date.now() - startTime;
|
|
147
|
+
requestLogger.error(`Request failed after ${duration}ms`, error instanceof Error ? error : new Error(String(error)));
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Stream events from the orchestrator in real-time
|
|
153
|
+
*/
|
|
154
|
+
async *stream(request) {
|
|
155
|
+
if (!this.orchestratorAgent) {
|
|
156
|
+
throw new Error("Orchestrator not initialized. Call initialize() first.");
|
|
157
|
+
}
|
|
158
|
+
// Generate correlation ID for request and store it for tool access
|
|
159
|
+
const correlationId = generateCorrelationId();
|
|
160
|
+
this.currentCorrelationId = correlationId;
|
|
161
|
+
const requestLogger = this.logger.withCorrelationId(correlationId);
|
|
162
|
+
requestLogger.info(`Streaming request: ${request.substring(0, 100)}...`, {
|
|
163
|
+
requestLength: request.length,
|
|
164
|
+
});
|
|
165
|
+
const startTime = Date.now();
|
|
166
|
+
try {
|
|
167
|
+
for await (const event of this.orchestratorAgent.stream(request)) {
|
|
168
|
+
yield event;
|
|
169
|
+
}
|
|
170
|
+
const duration = Date.now() - startTime;
|
|
171
|
+
requestLogger.info(`Stream completed in ${duration}ms`);
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
const duration = Date.now() - startTime;
|
|
175
|
+
requestLogger.error(`Stream failed after ${duration}ms`, error instanceof Error ? error : new Error(String(error)));
|
|
176
|
+
throw error;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Clear agent cache
|
|
181
|
+
*/
|
|
182
|
+
clearCache() {
|
|
183
|
+
clearToolCache();
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Get the agent registry (for inspection/debugging)
|
|
187
|
+
*/
|
|
188
|
+
getRegistry() {
|
|
189
|
+
return new Map(this.registry);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Wrap tools with error handling and logging
|
|
193
|
+
*/
|
|
194
|
+
wrapToolsWithErrorHandling(tools) {
|
|
195
|
+
return tools.map((originalTool) => {
|
|
196
|
+
const agentName = originalTool.name.replace(/^agent_/, "");
|
|
197
|
+
const sop = this.registry.get(agentName);
|
|
198
|
+
const wrappedInvoke = async (input) => {
|
|
199
|
+
// Get logger with current correlation ID and agent name
|
|
200
|
+
const agentLogger = this.currentCorrelationId
|
|
201
|
+
? this.logger
|
|
202
|
+
.withCorrelationId(this.currentCorrelationId)
|
|
203
|
+
.withAgent(agentName)
|
|
204
|
+
: this.logger.withAgent(agentName);
|
|
205
|
+
const task = input.task;
|
|
206
|
+
const startTime = Date.now();
|
|
207
|
+
agentLogger.debug("Tool invoke called", { input });
|
|
208
|
+
// Ensure agent is created with logger for model info
|
|
209
|
+
if (sop) {
|
|
210
|
+
getOrCreateAgent(sop, agentLogger);
|
|
211
|
+
}
|
|
212
|
+
agentLogger.info(`Invoking agent with task: "${task?.substring(0, 80) ?? "NO TASK"}..."`);
|
|
213
|
+
try {
|
|
214
|
+
const result = await originalTool.invoke(input);
|
|
215
|
+
const duration = Date.now() - startTime;
|
|
216
|
+
// Log completion with output preview
|
|
217
|
+
const outputPreview = result.substring(0, 200);
|
|
218
|
+
agentLogger.info(`Completed in ${duration}ms (${result.length} chars)`);
|
|
219
|
+
agentLogger.debug(`Output preview: ${outputPreview}...`);
|
|
220
|
+
return result;
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
const duration = Date.now() - startTime;
|
|
224
|
+
const originalError = error instanceof Error ? error : new Error(String(error));
|
|
225
|
+
agentLogger.error(`Failed after ${duration}ms: ${originalError.message}`, originalError);
|
|
226
|
+
if (this._config.errorMode === "fail-fast") {
|
|
227
|
+
throw new AgentInvocationError(agentName, task, originalError);
|
|
228
|
+
}
|
|
229
|
+
return JSON.stringify({
|
|
230
|
+
success: false,
|
|
231
|
+
agentName,
|
|
232
|
+
error: {
|
|
233
|
+
message: originalError.message,
|
|
234
|
+
code: "AGENT_INVOCATION_ERROR",
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
// Wrapped stream generator with logging
|
|
240
|
+
const wrappedStream = (toolContext) => {
|
|
241
|
+
const streamLogger = this.currentCorrelationId
|
|
242
|
+
? this.logger
|
|
243
|
+
.withCorrelationId(this.currentCorrelationId)
|
|
244
|
+
.withAgent(agentName)
|
|
245
|
+
: this.logger.withAgent(agentName);
|
|
246
|
+
const input = toolContext.toolUse.input;
|
|
247
|
+
const task = input?.task;
|
|
248
|
+
// Ensure agent is created with logger for model info
|
|
249
|
+
if (sop) {
|
|
250
|
+
getOrCreateAgent(sop, streamLogger);
|
|
251
|
+
}
|
|
252
|
+
streamLogger.info(`Invoking agent with task: "${task?.substring(0, 80) ?? "NO TASK"}..."`);
|
|
253
|
+
// Return the original stream - logging happens at invoke level
|
|
254
|
+
return originalTool.stream(toolContext);
|
|
255
|
+
};
|
|
256
|
+
// Create a new tool object with the wrapped invoke and stream
|
|
257
|
+
const wrappedTool = {
|
|
258
|
+
name: originalTool.name,
|
|
259
|
+
description: originalTool.description,
|
|
260
|
+
toolSpec: originalTool.toolSpec,
|
|
261
|
+
invoke: wrappedInvoke,
|
|
262
|
+
stream: wrappedStream,
|
|
263
|
+
};
|
|
264
|
+
return wrappedTool;
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Factory function to create and initialize an orchestrator
|
|
270
|
+
*/
|
|
271
|
+
export async function createOrchestrator(config = {}) {
|
|
272
|
+
const orchestrator = new OrchestratorImpl(config);
|
|
273
|
+
await orchestrator.initialize();
|
|
274
|
+
return orchestrator;
|
|
275
|
+
}
|
|
276
|
+
//# sourceMappingURL=orchestrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator.js","sourceRoot":"","sources":["../../src/orchestrator/orchestrator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EACN,UAAU,IAAI,cAAc,EAC5B,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,GACjB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAsB,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAa1D;;GAEG;AACH,SAAS,qBAAqB;IAC7B,OAAO,OAAO,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;AAC1E,CAAC;AAcD;;GAEG;AACH,MAAM,OAAO,gBAAgB;IACX,OAAO,CAA6B;IAC7C,QAAQ,GAA+B,IAAI,GAAG,EAAE,CAAC;IACjD,iBAAiB,GAAiB,IAAI,CAAC;IACvC,eAAe,GAAyB,IAAI,CAAC;IAC7C,MAAM,CAAS;IACf,oBAAoB,CAAU;IAEtC,YAAY,SAA6B,EAAE;QAC1C,IAAI,CAAC,OAAO,GAAG;YACd,SAAS,EAAE,MAAM,CAAC,SAAS,IA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OAAO,CAAC,KAAgC,CAAC;gBACnE,MAAM,IAAI,GAAG,KAAK,EAAE,IAAc,CAAC;gBAEnC,qDAAqD;gBACrD,IAAI,GAAG,EAAE,CAAC;oBACT,gBAAgB,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;gBACrC,CAAC;gBAED,YAAY,CAAC,IAAI,CAChB,8BAA8B,IAAI,EAAE,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,SAAS,MAAM,CACvE,CAAC;gBAEF,+DAA+D;gBAC/D,OAAO,YAAY,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YACzC,CAAC,CAAC;YAEF,8DAA8D;YAC9D,MAAM,WAAW,GAAmD;gBACnE,IAAI,EAAE,YAAY,CAAC,IAAI;gBACvB,WAAW,EAAE,YAAY,CAAC,WAAW;gBACrC,QAAQ,EAAE,YAAY,CAAC,QAAQ;gBAC/B,MAAM,EAAE,aAAa;gBACrB,MAAM,EAAE,aAAa;aACrB,CAAC;YAEF,OAAO,WAAW,CAAC;QACpB,CAAC,CAAC,CAAC;IACJ,CAAC;CACD;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACvC,SAA6B,EAAE;IAE/B,MAAM,YAAY,GAAG,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAClD,MAAM,YAAY,CAAC,UAAU,EAAE,CAAC;IAChC,OAAO,YAAY,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { InvokeResult, Orchestrator, OrchestratorConfig, OrchestratorStreamEvent, SOPDefinition } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* OrchestratorImpl class implementing the Orchestrator interface
|
|
4
|
+
*/
|
|
5
|
+
export declare class OrchestratorImpl implements Orchestrator {
|
|
6
|
+
private readonly _config;
|
|
7
|
+
private registry;
|
|
8
|
+
private orchestratorAgent;
|
|
9
|
+
private orchestratorSOP;
|
|
10
|
+
private logger;
|
|
11
|
+
private currentCorrelationId?;
|
|
12
|
+
constructor(config?: OrchestratorConfig);
|
|
13
|
+
/**
|
|
14
|
+
* Current configuration (readonly for inspection)
|
|
15
|
+
*/
|
|
16
|
+
get config(): OrchestratorConfig;
|
|
17
|
+
/**
|
|
18
|
+
* Initialize the orchestrator by discovering agents and creating tools
|
|
19
|
+
*/
|
|
20
|
+
initialize(): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Process a request through the orchestrator agent
|
|
23
|
+
*/
|
|
24
|
+
invoke(request: string): Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Process a request and return detailed result including thinking
|
|
27
|
+
*/
|
|
28
|
+
invokeWithDetails(request: string): Promise<InvokeResult>;
|
|
29
|
+
/**
|
|
30
|
+
* Stream events from the orchestrator in real-time
|
|
31
|
+
*/
|
|
32
|
+
stream(request: string): AsyncGenerator<OrchestratorStreamEvent>;
|
|
33
|
+
/**
|
|
34
|
+
* Clear agent cache
|
|
35
|
+
*/
|
|
36
|
+
clearCache(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Get the agent registry (for inspection/debugging)
|
|
39
|
+
*/
|
|
40
|
+
getRegistry(): Map<string, SOPDefinition>;
|
|
41
|
+
/**
|
|
42
|
+
* Wrap tools with error handling and logging
|
|
43
|
+
*/
|
|
44
|
+
private wrapToolsWithErrorHandling;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Factory function to create and initialize an orchestrator
|
|
48
|
+
*/
|
|
49
|
+
export declare function createOrchestrator(config?: OrchestratorConfig): Promise<Orchestrator>;
|
|
50
|
+
//# sourceMappingURL=orchestrator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orchestrator.d.ts","sourceRoot":"","sources":["../src/orchestrator.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAEX,YAAY,EAGZ,YAAY,EACZ,kBAAkB,EAClB,uBAAuB,EACvB,aAAa,EACb,MAAM,YAAY,CAAC;AAqBpB;;GAEG;AACH,qBAAa,gBAAiB,YAAW,YAAY;IACpD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6B;IACrD,OAAO,CAAC,QAAQ,CAAyC;IACzD,OAAO,CAAC,iBAAiB,CAAsB;IAC/C,OAAO,CAAC,eAAe,CAA8B;IACrD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,oBAAoB,CAAC,CAAS;gBAE1B,MAAM,GAAE,kBAAuB;IAmB3C;;OAEG;IACH,IAAI,MAAM,IAAI,kBAAkB,CAE/B;IAED;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAoCjC;;OAEG;IACG,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAK9C;;OAEG;IACG,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAgG/D;;OAEG;IACI,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,CAAC,uBAAuB,CAAC;IAiCvE;;OAEG;IACH,UAAU,IAAI,IAAI;IAIlB;;OAEG;IACH,WAAW,IAAI,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC;IAIzC;;OAEG;IACH,OAAO,CAAC,0BAA0B;CAwGlC;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACvC,MAAM,GAAE,kBAAuB,GAC7B,OAAO,CAAC,YAAY,CAAC,CAIvB"}
|