@ddse/acm-adapters 0.5.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 +228 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/langgraph.d.ts +81 -0
- package/dist/langgraph.d.ts.map +1 -0
- package/dist/langgraph.js +222 -0
- package/dist/langgraph.js.map +1 -0
- package/dist/msaf.d.ts +76 -0
- package/dist/msaf.d.ts.map +1 -0
- package/dist/msaf.js +269 -0
- package/dist/msaf.js.map +1 -0
- package/package.json +42 -0
- package/src/index.ts +3 -0
- package/src/langgraph.ts +312 -0
- package/src/msaf.ts +361 -0
- package/tsconfig.json +12 -0
- package/tsconfig.tsbuildinfo +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 DDSE Foundation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# @ddse/acm-adapters
|
|
2
|
+
|
|
3
|
+
Framework adapters for ACM, providing integration with LangGraph and Microsoft Agent Framework.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides adapters that allow ACM plans to be executed using popular agent frameworks. The adapters handle the conversion of ACM tasks, guards, and edges into framework-specific constructs while preserving ACM's policy, verification, and streaming capabilities.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **LangGraph Adapter**: Convert ACM plans into LangGraph state graphs
|
|
12
|
+
- **MS Agent Framework Adapter**: Execute ACM plans as MS Agent activities
|
|
13
|
+
- Full support for ACM policy hooks and verification
|
|
14
|
+
- Streaming progress updates
|
|
15
|
+
- Memory ledger integration
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pnpm add @ddse/acm-adapters
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
For LangGraph support, also install:
|
|
24
|
+
```bash
|
|
25
|
+
pnpm add @langchain/langgraph
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
### LangGraph Adapter
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { asLangGraph } from '@ddse/acm-adapters';
|
|
34
|
+
import { executePlan } from '@ddse/acm-runtime';
|
|
35
|
+
|
|
36
|
+
// Create adapter
|
|
37
|
+
const adapter = asLangGraph({
|
|
38
|
+
goal,
|
|
39
|
+
context,
|
|
40
|
+
plan,
|
|
41
|
+
capabilityRegistry,
|
|
42
|
+
toolRegistry,
|
|
43
|
+
policy,
|
|
44
|
+
stream,
|
|
45
|
+
ledger,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Get graph structure for use with LangGraph
|
|
49
|
+
const { nodes, edges, entryPoint } = adapter.buildGraph();
|
|
50
|
+
|
|
51
|
+
// Or execute directly (simplified execution)
|
|
52
|
+
const result = await adapter.execute();
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Microsoft Agent Framework Adapter
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { wrapAgentNodes } from '@ddse/acm-adapters';
|
|
59
|
+
|
|
60
|
+
// Create adapter
|
|
61
|
+
const adapter = wrapAgentNodes({
|
|
62
|
+
goal,
|
|
63
|
+
context,
|
|
64
|
+
plan,
|
|
65
|
+
capabilityRegistry,
|
|
66
|
+
toolRegistry,
|
|
67
|
+
policy,
|
|
68
|
+
stream,
|
|
69
|
+
ledger,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Get activities for MS Agent Framework
|
|
73
|
+
const activities = adapter.getAllActivities();
|
|
74
|
+
|
|
75
|
+
// Or execute directly
|
|
76
|
+
const result = await adapter.execute();
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Full Example with CLI
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { asLangGraph, wrapAgentNodes } from '@ddse/acm-adapters';
|
|
83
|
+
|
|
84
|
+
// ... setup goal, context, plan, registries ...
|
|
85
|
+
|
|
86
|
+
let result;
|
|
87
|
+
|
|
88
|
+
if (engine === 'langgraph') {
|
|
89
|
+
const adapter = asLangGraph({
|
|
90
|
+
goal,
|
|
91
|
+
context,
|
|
92
|
+
plan,
|
|
93
|
+
capabilityRegistry,
|
|
94
|
+
toolRegistry,
|
|
95
|
+
policy,
|
|
96
|
+
stream,
|
|
97
|
+
ledger,
|
|
98
|
+
});
|
|
99
|
+
result = await adapter.execute();
|
|
100
|
+
} else if (engine === 'msaf') {
|
|
101
|
+
const adapter = wrapAgentNodes({
|
|
102
|
+
goal,
|
|
103
|
+
context,
|
|
104
|
+
plan,
|
|
105
|
+
capabilityRegistry,
|
|
106
|
+
toolRegistry,
|
|
107
|
+
policy,
|
|
108
|
+
stream,
|
|
109
|
+
ledger,
|
|
110
|
+
});
|
|
111
|
+
result = await adapter.execute();
|
|
112
|
+
} else {
|
|
113
|
+
// Use standard ACM runtime
|
|
114
|
+
result = await executePlan({
|
|
115
|
+
goal,
|
|
116
|
+
context,
|
|
117
|
+
plan,
|
|
118
|
+
capabilityRegistry,
|
|
119
|
+
toolRegistry,
|
|
120
|
+
policy,
|
|
121
|
+
stream,
|
|
122
|
+
ledger,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Features by Adapter
|
|
128
|
+
|
|
129
|
+
### LangGraph Adapter
|
|
130
|
+
|
|
131
|
+
The LangGraph adapter converts ACM plans into LangGraph state graphs:
|
|
132
|
+
|
|
133
|
+
- **Nodes**: Each ACM task becomes a LangGraph node
|
|
134
|
+
- **Edges**: ACM edges with guards become conditional edges
|
|
135
|
+
- **State**: Graph state includes task outputs and context
|
|
136
|
+
- **Execution**: Supports LangGraph's execution engine
|
|
137
|
+
|
|
138
|
+
**Key Methods:**
|
|
139
|
+
- `buildGraph()`: Get nodes, edges, and entry point
|
|
140
|
+
- `execute()`: Run simplified execution
|
|
141
|
+
|
|
142
|
+
### MS Agent Framework Adapter
|
|
143
|
+
|
|
144
|
+
The MS Agent Framework adapter wraps ACM tasks as activities:
|
|
145
|
+
|
|
146
|
+
- **Activities**: Each ACM task becomes an activity handler
|
|
147
|
+
- **Workflow**: Respects task dependencies via topological sort
|
|
148
|
+
- **Hooks**: Full policy and verification support
|
|
149
|
+
- **Events**: Streaming events for progress tracking
|
|
150
|
+
|
|
151
|
+
**Key Methods:**
|
|
152
|
+
- `getActivity(taskId)`: Get activity handler for a task
|
|
153
|
+
- `getAllActivities()`: Get all activity handlers
|
|
154
|
+
- `execute()`: Run workflow execution
|
|
155
|
+
|
|
156
|
+
## Policy and Verification
|
|
157
|
+
|
|
158
|
+
Both adapters fully support ACM's policy and verification features:
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
// Policy checks happen before task execution
|
|
162
|
+
const policy = {
|
|
163
|
+
async evaluate({ action, input, context }) {
|
|
164
|
+
// Return true to allow, false to deny
|
|
165
|
+
return input.riskLevel !== 'HIGH';
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
// Verification happens after task execution
|
|
170
|
+
class MyTask extends Task {
|
|
171
|
+
verification() {
|
|
172
|
+
return ['output.result !== null', 'output.status === "success"'];
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Streaming
|
|
178
|
+
|
|
179
|
+
Both adapters emit progress events that can be consumed:
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
const stream = new DefaultStreamSink();
|
|
183
|
+
stream.attach('task', (update) => {
|
|
184
|
+
console.log(`Task ${update.taskId}: ${update.status}`);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// Use with adapter
|
|
188
|
+
const adapter = asLangGraph({
|
|
189
|
+
// ...
|
|
190
|
+
stream,
|
|
191
|
+
});
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## API Reference
|
|
195
|
+
|
|
196
|
+
### LangGraphAdapter
|
|
197
|
+
|
|
198
|
+
**Constructor:**
|
|
199
|
+
```typescript
|
|
200
|
+
new LangGraphAdapter(options: LangGraphAdapterOptions)
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
**Methods:**
|
|
204
|
+
- `buildGraph()`: Returns `{ nodes, edges, entryPoint }`
|
|
205
|
+
- `execute()`: Returns `{ outputs, ledger }`
|
|
206
|
+
|
|
207
|
+
### MSAgentFrameworkAdapter
|
|
208
|
+
|
|
209
|
+
**Constructor:**
|
|
210
|
+
```typescript
|
|
211
|
+
new MSAgentFrameworkAdapter(options: MSAgentFrameworkAdapterOptions)
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
**Methods:**
|
|
215
|
+
- `getActivity(taskId: string)`: Get activity handler
|
|
216
|
+
- `getAllActivities()`: Get all activities as Map
|
|
217
|
+
- `execute()`: Returns `{ outputs, ledger }`
|
|
218
|
+
|
|
219
|
+
## Notes
|
|
220
|
+
|
|
221
|
+
- The adapters provide simplified execution modes suitable for ACM use cases
|
|
222
|
+
- For advanced LangGraph features (checkpointing, parallel execution), use the graph structure directly
|
|
223
|
+
- MS Agent Framework adapter uses topological sorting for task ordering
|
|
224
|
+
- Both adapters respect guard expressions for conditional branching
|
|
225
|
+
|
|
226
|
+
## License
|
|
227
|
+
|
|
228
|
+
Apache-2.0
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { LangGraphAdapter, asLangGraph, type LangGraphAdapterOptions, type GraphState } from './langgraph.js';
|
|
2
|
+
export { MSAgentFrameworkAdapter, wrapAgentNodes, type MSAgentFrameworkAdapterOptions, type ActivityState } from './msaf.js';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,KAAK,uBAAuB,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC9G,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,KAAK,8BAA8B,EAAE,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAiD,MAAM,gBAAgB,CAAC;AAC9G,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAA2D,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type Goal, type Context, type Plan, type CapabilityRegistry, type ToolRegistry, type PolicyEngine, type StreamSink, type NucleusFactory, type NucleusConfig } from '@ddse/acm-sdk';
|
|
2
|
+
import type { MemoryLedger } from '@ddse/acm-runtime';
|
|
3
|
+
/**
|
|
4
|
+
* LangGraph adapter options
|
|
5
|
+
*/
|
|
6
|
+
export interface LangGraphAdapterOptions {
|
|
7
|
+
goal: Goal;
|
|
8
|
+
context: Context;
|
|
9
|
+
plan: Plan;
|
|
10
|
+
capabilityRegistry: CapabilityRegistry;
|
|
11
|
+
toolRegistry: ToolRegistry;
|
|
12
|
+
policy?: PolicyEngine;
|
|
13
|
+
stream?: StreamSink;
|
|
14
|
+
ledger?: MemoryLedger;
|
|
15
|
+
resumeFrom?: string;
|
|
16
|
+
checkpointStore?: any;
|
|
17
|
+
nucleusFactory: NucleusFactory;
|
|
18
|
+
nucleusConfig: {
|
|
19
|
+
llmCall: NucleusConfig['llmCall'];
|
|
20
|
+
hooks?: NucleusConfig['hooks'];
|
|
21
|
+
allowedTools?: string[];
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* LangGraph node state
|
|
26
|
+
*/
|
|
27
|
+
export interface GraphState {
|
|
28
|
+
taskId: string;
|
|
29
|
+
input: any;
|
|
30
|
+
output?: any;
|
|
31
|
+
error?: Error;
|
|
32
|
+
context: Context;
|
|
33
|
+
outputs: Map<string, any>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Convert ACM Plan to LangGraph-compatible structure
|
|
37
|
+
*
|
|
38
|
+
* This adapter converts ACM tasks and edges into LangGraph nodes and edges.
|
|
39
|
+
* Each ACM task becomes a LangGraph node, and guards become conditional edges.
|
|
40
|
+
*/
|
|
41
|
+
export declare class LangGraphAdapter {
|
|
42
|
+
private options;
|
|
43
|
+
constructor(options: LangGraphAdapterOptions);
|
|
44
|
+
/**
|
|
45
|
+
* Create a LangGraph-compatible node function from an ACM task
|
|
46
|
+
*/
|
|
47
|
+
private createNodeFunction;
|
|
48
|
+
/**
|
|
49
|
+
* Create guard evaluator for conditional edges
|
|
50
|
+
*/
|
|
51
|
+
private createGuardEvaluator;
|
|
52
|
+
/**
|
|
53
|
+
* Build LangGraph structure
|
|
54
|
+
*
|
|
55
|
+
* Returns a configuration object that can be used with LangGraph's StateGraph
|
|
56
|
+
*/
|
|
57
|
+
buildGraph(): {
|
|
58
|
+
nodes: Map<string, (state: GraphState) => Promise<Partial<GraphState>>>;
|
|
59
|
+
edges: Array<{
|
|
60
|
+
from: string;
|
|
61
|
+
to: string;
|
|
62
|
+
condition?: (state: GraphState) => boolean;
|
|
63
|
+
}>;
|
|
64
|
+
entryPoint: string;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Execute the plan using LangGraph (if available)
|
|
68
|
+
*
|
|
69
|
+
* Note: This is a simplified implementation. In practice, you would use
|
|
70
|
+
* LangGraph's StateGraph API directly with the graph structure.
|
|
71
|
+
*/
|
|
72
|
+
execute(): Promise<{
|
|
73
|
+
outputsByTask: Record<string, any>;
|
|
74
|
+
ledger: readonly any[];
|
|
75
|
+
}>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Helper function to create a LangGraph adapter
|
|
79
|
+
*/
|
|
80
|
+
export declare function asLangGraph(options: LangGraphAdapterOptions): LangGraphAdapter;
|
|
81
|
+
//# sourceMappingURL=langgraph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"langgraph.d.ts","sourceRoot":"","sources":["../src/langgraph.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,IAAI,EACT,KAAK,OAAO,EACZ,KAAK,IAAI,EACT,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,UAAU,EAEf,KAAK,cAAc,EAC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O,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACxE,KAAK,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,EAAE,EAAE,MAAM,CAAC;YAAC,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,OAAO,CAAA;SAAE,CAAC,CAAC;QACvF,UAAU,EAAE,MAAM,CAAC;KACpB;IA8BD;;;;;OAKG;IACG,OAAO,IAAI,OAAO,CAAC;QAAE,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAAC,MAAM,EAAE,SAAS,GAAG,EAAE,CAAA;KAAE,CAAC;CA0CzF;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,uBAAuB,GAAG,gBAAgB,CAE9E"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// LangGraph Adapter for ACM
|
|
2
|
+
import { InternalContextScopeImpl, } from '@ddse/acm-sdk';
|
|
3
|
+
import { createInstrumentedToolGetter } from '@ddse/acm-runtime';
|
|
4
|
+
/**
|
|
5
|
+
* Convert ACM Plan to LangGraph-compatible structure
|
|
6
|
+
*
|
|
7
|
+
* This adapter converts ACM tasks and edges into LangGraph nodes and edges.
|
|
8
|
+
* Each ACM task becomes a LangGraph node, and guards become conditional edges.
|
|
9
|
+
*/
|
|
10
|
+
export class LangGraphAdapter {
|
|
11
|
+
options;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.options = options;
|
|
14
|
+
// Warn if resume options are provided but not supported
|
|
15
|
+
if (options.resumeFrom || options.checkpointStore) {
|
|
16
|
+
console.warn('⚠️ LangGraph adapter does not support resume functionality. ' +
|
|
17
|
+
'Use the runtime engine (--engine runtime) for resumable executions.');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create a LangGraph-compatible node function from an ACM task
|
|
22
|
+
*/
|
|
23
|
+
createNodeFunction(taskId) {
|
|
24
|
+
return async (state) => {
|
|
25
|
+
const { plan, capabilityRegistry, toolRegistry, policy, stream, ledger } = this.options;
|
|
26
|
+
// Find task spec in plan
|
|
27
|
+
const taskSpec = plan.tasks.find((t) => t.id === taskId);
|
|
28
|
+
if (!taskSpec) {
|
|
29
|
+
throw new Error(`Task ${taskId} not found in plan`);
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
// Get task implementation
|
|
33
|
+
const capabilityName = taskSpec.capabilityRef || taskSpec.capability;
|
|
34
|
+
if (!capabilityName) {
|
|
35
|
+
throw new Error(`Task ${taskId} missing capability reference`);
|
|
36
|
+
}
|
|
37
|
+
const task = capabilityRegistry.resolve(capabilityName);
|
|
38
|
+
if (!task) {
|
|
39
|
+
throw new Error(`Capability ${capabilityName} not found`);
|
|
40
|
+
}
|
|
41
|
+
// Build run context
|
|
42
|
+
const allowedTools = new Set(this.options.nucleusConfig.allowedTools ?? []);
|
|
43
|
+
for (const tool of taskSpec.tools ?? []) {
|
|
44
|
+
allowedTools.add(tool.name);
|
|
45
|
+
}
|
|
46
|
+
const nucleus = this.options.nucleusFactory({
|
|
47
|
+
goalId: this.options.goal.id,
|
|
48
|
+
goalIntent: this.options.goal.intent,
|
|
49
|
+
planId: plan.id,
|
|
50
|
+
taskId,
|
|
51
|
+
contextRef: plan.contextRef,
|
|
52
|
+
context: state.context,
|
|
53
|
+
llmCall: this.options.nucleusConfig.llmCall,
|
|
54
|
+
hooks: this.options.nucleusConfig.hooks,
|
|
55
|
+
allowedTools: Array.from(allowedTools),
|
|
56
|
+
});
|
|
57
|
+
const internalScope = new InternalContextScopeImpl(entry => {
|
|
58
|
+
this.options.ledger?.append(entry.type, entry.details);
|
|
59
|
+
});
|
|
60
|
+
nucleus.setInternalContext(internalScope);
|
|
61
|
+
const getTool = createInstrumentedToolGetter({
|
|
62
|
+
taskId,
|
|
63
|
+
capability: capabilityName,
|
|
64
|
+
toolRegistry,
|
|
65
|
+
ledger: this.options.ledger,
|
|
66
|
+
});
|
|
67
|
+
const runContext = {
|
|
68
|
+
goal: this.options.goal,
|
|
69
|
+
context: state.context,
|
|
70
|
+
outputs: Object.fromEntries(state.outputs),
|
|
71
|
+
metrics: { costUsd: 0, elapsedSec: 0 },
|
|
72
|
+
getTool,
|
|
73
|
+
getCapabilityRegistry: () => capabilityRegistry,
|
|
74
|
+
stream,
|
|
75
|
+
nucleus,
|
|
76
|
+
internalContext: internalScope,
|
|
77
|
+
};
|
|
78
|
+
const preflight = await nucleus.preflight();
|
|
79
|
+
if (preflight.status === 'NEEDS_CONTEXT') {
|
|
80
|
+
throw new Error(`Task ${taskId} requires additional context retrieval: ${preflight.retrievalDirectives.join(', ')}`);
|
|
81
|
+
}
|
|
82
|
+
// Policy pre-check
|
|
83
|
+
if (policy) {
|
|
84
|
+
const policyInput = task.policyInput?.(runContext, taskSpec.input || state.input) || {};
|
|
85
|
+
const decision = await policy.evaluate('task.pre', {
|
|
86
|
+
action: taskSpec.capability,
|
|
87
|
+
input: policyInput,
|
|
88
|
+
context: state.context,
|
|
89
|
+
});
|
|
90
|
+
if (!decision.allow) {
|
|
91
|
+
throw new Error(`Policy denied execution of ${taskSpec.capability}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Execute task
|
|
95
|
+
stream?.emit('task', { taskId, status: 'started' });
|
|
96
|
+
const output = await task.execute(runContext, taskSpec.input || state.input);
|
|
97
|
+
// Update outputs map
|
|
98
|
+
const newOutputs = new Map(state.outputs);
|
|
99
|
+
newOutputs.set(taskId, output);
|
|
100
|
+
stream?.emit('task', { taskId, status: 'completed', output });
|
|
101
|
+
// Log to ledger
|
|
102
|
+
if (ledger) {
|
|
103
|
+
ledger.append('TASK_END', { taskId, capability: taskSpec.capability });
|
|
104
|
+
}
|
|
105
|
+
const postcheck = await nucleus.postcheck(output);
|
|
106
|
+
if (postcheck.status === 'NEEDS_COMPENSATION' || postcheck.status === 'ESCALATE') {
|
|
107
|
+
throw new Error(`Task ${taskId} postcheck failed: ${postcheck.reason}`);
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
taskId,
|
|
111
|
+
output,
|
|
112
|
+
outputs: newOutputs,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
stream?.emit('task', { taskId, status: 'failed', error });
|
|
117
|
+
if (ledger) {
|
|
118
|
+
ledger.append('ERROR', { taskId, error: String(error) });
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
taskId,
|
|
122
|
+
error: error,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Create guard evaluator for conditional edges
|
|
129
|
+
*/
|
|
130
|
+
createGuardEvaluator(guard) {
|
|
131
|
+
if (!guard) {
|
|
132
|
+
return () => true;
|
|
133
|
+
}
|
|
134
|
+
return (state) => {
|
|
135
|
+
try {
|
|
136
|
+
// Simple guard evaluation
|
|
137
|
+
const func = new Function('state', 'outputs', `return ${guard}`);
|
|
138
|
+
return func(state, Object.fromEntries(state.outputs));
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Build LangGraph structure
|
|
147
|
+
*
|
|
148
|
+
* Returns a configuration object that can be used with LangGraph's StateGraph
|
|
149
|
+
*/
|
|
150
|
+
buildGraph() {
|
|
151
|
+
const { plan } = this.options;
|
|
152
|
+
const nodes = new Map();
|
|
153
|
+
const edges = [];
|
|
154
|
+
// Create nodes for each task
|
|
155
|
+
for (const task of plan.tasks) {
|
|
156
|
+
nodes.set(task.id, this.createNodeFunction(task.id));
|
|
157
|
+
}
|
|
158
|
+
// Create edges
|
|
159
|
+
for (const edge of plan.edges) {
|
|
160
|
+
edges.push({
|
|
161
|
+
from: edge.from,
|
|
162
|
+
to: edge.to,
|
|
163
|
+
condition: edge.guard ? this.createGuardEvaluator(edge.guard) : undefined,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
// Find entry point (task with no incoming edges)
|
|
167
|
+
const hasIncoming = new Set(plan.edges.map((e) => e.to));
|
|
168
|
+
const entryPoint = plan.tasks.find((t) => !hasIncoming.has(t.id))?.id || plan.tasks[0]?.id;
|
|
169
|
+
if (!entryPoint) {
|
|
170
|
+
throw new Error('No entry point found in plan');
|
|
171
|
+
}
|
|
172
|
+
return { nodes, edges, entryPoint };
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Execute the plan using LangGraph (if available)
|
|
176
|
+
*
|
|
177
|
+
* Note: This is a simplified implementation. In practice, you would use
|
|
178
|
+
* LangGraph's StateGraph API directly with the graph structure.
|
|
179
|
+
*/
|
|
180
|
+
async execute() {
|
|
181
|
+
const { nodes, edges, entryPoint } = this.buildGraph();
|
|
182
|
+
// Initialize state
|
|
183
|
+
const state = {
|
|
184
|
+
taskId: entryPoint,
|
|
185
|
+
input: {},
|
|
186
|
+
context: this.options.context,
|
|
187
|
+
outputs: new Map(),
|
|
188
|
+
};
|
|
189
|
+
// Simple sequential execution based on edges
|
|
190
|
+
// In a real implementation, this would use LangGraph's execution engine
|
|
191
|
+
let currentTaskId = entryPoint;
|
|
192
|
+
const visited = new Set();
|
|
193
|
+
while (currentTaskId && !visited.has(currentTaskId)) {
|
|
194
|
+
visited.add(currentTaskId);
|
|
195
|
+
const nodeFunc = nodes.get(currentTaskId);
|
|
196
|
+
if (!nodeFunc)
|
|
197
|
+
break;
|
|
198
|
+
const result = await nodeFunc(state);
|
|
199
|
+
Object.assign(state, result);
|
|
200
|
+
// Find next task
|
|
201
|
+
const outgoingEdges = edges.filter((e) => e.from === currentTaskId);
|
|
202
|
+
currentTaskId = null;
|
|
203
|
+
for (const edge of outgoingEdges) {
|
|
204
|
+
if (!edge.condition || edge.condition(state)) {
|
|
205
|
+
currentTaskId = edge.to;
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
outputsByTask: Object.fromEntries(state.outputs),
|
|
212
|
+
ledger: this.options.ledger?.getEntries() || [],
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Helper function to create a LangGraph adapter
|
|
218
|
+
*/
|
|
219
|
+
export function asLangGraph(options) {
|
|
220
|
+
return new LangGraphAdapter(options);
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=langgraph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"langgraph.js","sourceRoot":"","sources":["../src/langgraph.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,OAAO,EACL,wBAAwB,GAWzB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAC;AAqCjE;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IACP;IAApB,YAAoB,OAAgC;QAAhC,YAAO,GAAP,OAAO,CAAyB;QAClD,wDAAwD;QACxD,IAAI,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;YAClD,OAAO,CAAC,IAAI,CACV,+DAA+D;gBAC/D,qEAAqE,CACtE,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;OAEG;IACK,kBAAkB,CAAC,MAAc;QACvC,OAAO,KAAK,EAAE,KAAiB,EAAgC,EAAE;YAC/D,MAAM,EAAE,IAAI,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;YAExF,yBAAyB;YACzB,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,MAAM,CAAC,CAAC;YACzD,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,MAAM,IAAI,KAAK,CAAC,QAAQ,MAAM,oBAAoB,CAA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,OAAO,CAAC,CAAC;AACvC,CAAC"}
|
package/dist/msaf.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { type Goal, type Context, type Plan, type CapabilityRegistry, type ToolRegistry, type PolicyEngine, type StreamSink, type NucleusFactory, type NucleusConfig } from '@ddse/acm-sdk';
|
|
2
|
+
import type { MemoryLedger } from '@ddse/acm-runtime';
|
|
3
|
+
/**
|
|
4
|
+
* MS Agent Framework adapter options
|
|
5
|
+
*/
|
|
6
|
+
export interface MSAgentFrameworkAdapterOptions {
|
|
7
|
+
goal: Goal;
|
|
8
|
+
context: Context;
|
|
9
|
+
plan: Plan;
|
|
10
|
+
capabilityRegistry: CapabilityRegistry;
|
|
11
|
+
toolRegistry: ToolRegistry;
|
|
12
|
+
policy?: PolicyEngine;
|
|
13
|
+
stream?: StreamSink;
|
|
14
|
+
ledger?: MemoryLedger;
|
|
15
|
+
resumeFrom?: string;
|
|
16
|
+
checkpointStore?: any;
|
|
17
|
+
nucleusFactory: NucleusFactory;
|
|
18
|
+
nucleusConfig: {
|
|
19
|
+
llmCall: NucleusConfig['llmCall'];
|
|
20
|
+
hooks?: NucleusConfig['hooks'];
|
|
21
|
+
allowedTools?: string[];
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Agent activity state
|
|
26
|
+
*/
|
|
27
|
+
export interface ActivityState {
|
|
28
|
+
taskId: string;
|
|
29
|
+
input: any;
|
|
30
|
+
output?: any;
|
|
31
|
+
context: Context;
|
|
32
|
+
outputs: Map<string, any>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Activity handler type
|
|
36
|
+
*/
|
|
37
|
+
export type ActivityHandler = (state: ActivityState) => Promise<any>;
|
|
38
|
+
/**
|
|
39
|
+
* Microsoft Agent Framework Adapter for ACM
|
|
40
|
+
*
|
|
41
|
+
* Converts ACM tasks into MS Agent Framework activities with proper
|
|
42
|
+
* hooks for policy, verification, and streaming.
|
|
43
|
+
*/
|
|
44
|
+
export declare class MSAgentFrameworkAdapter {
|
|
45
|
+
private options;
|
|
46
|
+
private activities;
|
|
47
|
+
constructor(options: MSAgentFrameworkAdapterOptions);
|
|
48
|
+
/**
|
|
49
|
+
* Build activity handlers from ACM tasks
|
|
50
|
+
*/
|
|
51
|
+
private buildActivities;
|
|
52
|
+
/**
|
|
53
|
+
* Get activity handler for a task
|
|
54
|
+
*/
|
|
55
|
+
getActivity(taskId: string): ActivityHandler | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Get all activities
|
|
58
|
+
*/
|
|
59
|
+
getAllActivities(): Map<string, ActivityHandler>;
|
|
60
|
+
/**
|
|
61
|
+
* Execute workflow using MS Agent Framework pattern
|
|
62
|
+
*/
|
|
63
|
+
execute(): Promise<{
|
|
64
|
+
outputsByTask: Record<string, any>;
|
|
65
|
+
ledger: readonly any[];
|
|
66
|
+
}>;
|
|
67
|
+
/**
|
|
68
|
+
* Topological sort of tasks based on edges
|
|
69
|
+
*/
|
|
70
|
+
private topologicalSort;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Helper function to create MS Agent Framework adapter
|
|
74
|
+
*/
|
|
75
|
+
export declare function wrapAgentNodes(options: MSAgentFrameworkAdapterOptions): MSAgentFrameworkAdapter;
|
|
76
|
+
//# sourceMappingURL=msaf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"msaf.d.ts","sourceRoot":"","sources":["../src/msaf.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,IAAI,EACT,KAAK,OAAO,EACZ,KAAK,IAAI,EACT,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,UAAU,EAEf,KAAK,cAAc,EACnB,KAAK,aAAa,EACnB,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C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