mojentic 1.0.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 +459 -0
- package/dist/agents/async-aggregator-agent.d.ts +101 -0
- package/dist/agents/async-aggregator-agent.d.ts.map +1 -0
- package/dist/agents/async-aggregator-agent.js +160 -0
- package/dist/agents/async-aggregator-agent.js.map +1 -0
- package/dist/agents/async-dispatcher.d.ts +98 -0
- package/dist/agents/async-dispatcher.d.ts.map +1 -0
- package/dist/agents/async-dispatcher.js +173 -0
- package/dist/agents/async-dispatcher.js.map +1 -0
- package/dist/agents/async-llm-agent-with-memory.d.ts +95 -0
- package/dist/agents/async-llm-agent-with-memory.d.ts.map +1 -0
- package/dist/agents/async-llm-agent-with-memory.js +136 -0
- package/dist/agents/async-llm-agent-with-memory.js.map +1 -0
- package/dist/agents/async-llm-agent.d.ts +85 -0
- package/dist/agents/async-llm-agent.d.ts.map +1 -0
- package/dist/agents/async-llm-agent.js +87 -0
- package/dist/agents/async-llm-agent.js.map +1 -0
- package/dist/agents/base-agent.d.ts +59 -0
- package/dist/agents/base-agent.d.ts.map +1 -0
- package/dist/agents/base-agent.js +24 -0
- package/dist/agents/base-agent.js.map +1 -0
- package/dist/agents/base-async-agent.d.ts +42 -0
- package/dist/agents/base-async-agent.d.ts.map +1 -0
- package/dist/agents/base-async-agent.js +6 -0
- package/dist/agents/base-async-agent.js.map +1 -0
- package/dist/agents/event.d.ts +26 -0
- package/dist/agents/event.d.ts.map +1 -0
- package/dist/agents/event.js +13 -0
- package/dist/agents/event.js.map +1 -0
- package/dist/agents/index.d.ts +14 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +30 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/iterative-problem-solver.d.ts +83 -0
- package/dist/agents/iterative-problem-solver.d.ts.map +1 -0
- package/dist/agents/iterative-problem-solver.js +120 -0
- package/dist/agents/iterative-problem-solver.js.map +1 -0
- package/dist/agents/router.d.ts +44 -0
- package/dist/agents/router.d.ts.map +1 -0
- package/dist/agents/router.js +53 -0
- package/dist/agents/router.js.map +1 -0
- package/dist/agents/simple-recursive-agent.d.ts +182 -0
- package/dist/agents/simple-recursive-agent.d.ts.map +1 -0
- package/dist/agents/simple-recursive-agent.js +272 -0
- package/dist/agents/simple-recursive-agent.js.map +1 -0
- package/dist/context/index.d.ts +5 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +21 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/shared-working-memory.d.ts +76 -0
- package/dist/context/shared-working-memory.d.ts.map +1 -0
- package/dist/context/shared-working-memory.js +121 -0
- package/dist/context/shared-working-memory.js.map +1 -0
- package/dist/error.d.ts +93 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +149 -0
- package/dist/error.js.map +1 -0
- package/dist/examples/react/decisioning-agent.d.ts +48 -0
- package/dist/examples/react/decisioning-agent.d.ts.map +1 -0
- package/dist/examples/react/decisioning-agent.js +204 -0
- package/dist/examples/react/decisioning-agent.js.map +1 -0
- package/dist/examples/react/events.d.ts +77 -0
- package/dist/examples/react/events.d.ts.map +1 -0
- package/dist/examples/react/events.js +9 -0
- package/dist/examples/react/events.js.map +1 -0
- package/dist/examples/react/formatters.d.ts +23 -0
- package/dist/examples/react/formatters.d.ts.map +1 -0
- package/dist/examples/react/formatters.js +68 -0
- package/dist/examples/react/formatters.js.map +1 -0
- package/dist/examples/react/index.d.ts +12 -0
- package/dist/examples/react/index.d.ts.map +1 -0
- package/dist/examples/react/index.js +28 -0
- package/dist/examples/react/index.js.map +1 -0
- package/dist/examples/react/models.d.ts +57 -0
- package/dist/examples/react/models.d.ts.map +1 -0
- package/dist/examples/react/models.js +19 -0
- package/dist/examples/react/models.js.map +1 -0
- package/dist/examples/react/output-agent.d.ts +23 -0
- package/dist/examples/react/output-agent.d.ts.map +1 -0
- package/dist/examples/react/output-agent.js +28 -0
- package/dist/examples/react/output-agent.js.map +1 -0
- package/dist/examples/react/summarization-agent.d.ts +46 -0
- package/dist/examples/react/summarization-agent.d.ts.map +1 -0
- package/dist/examples/react/summarization-agent.js +102 -0
- package/dist/examples/react/summarization-agent.js.map +1 -0
- package/dist/examples/react/thinking-agent.d.ts +47 -0
- package/dist/examples/react/thinking-agent.d.ts.map +1 -0
- package/dist/examples/react/thinking-agent.js +127 -0
- package/dist/examples/react/thinking-agent.js.map +1 -0
- package/dist/examples/react/tool-call-agent.d.ts +25 -0
- package/dist/examples/react/tool-call-agent.d.ts.map +1 -0
- package/dist/examples/react/tool-call-agent.js +83 -0
- package/dist/examples/react/tool-call-agent.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/llm/agent.d.ts +68 -0
- package/dist/llm/agent.d.ts.map +1 -0
- package/dist/llm/agent.js +85 -0
- package/dist/llm/agent.js.map +1 -0
- package/dist/llm/broker.d.ts +150 -0
- package/dist/llm/broker.d.ts.map +1 -0
- package/dist/llm/broker.js +355 -0
- package/dist/llm/broker.js.map +1 -0
- package/dist/llm/chat-session.d.ts +98 -0
- package/dist/llm/chat-session.d.ts.map +1 -0
- package/dist/llm/chat-session.js +156 -0
- package/dist/llm/chat-session.js.map +1 -0
- package/dist/llm/gateway.d.ts +28 -0
- package/dist/llm/gateway.d.ts.map +1 -0
- package/dist/llm/gateway.js +6 -0
- package/dist/llm/gateway.js.map +1 -0
- package/dist/llm/gateways/index.d.ts +9 -0
- package/dist/llm/gateways/index.d.ts.map +1 -0
- package/dist/llm/gateways/index.js +25 -0
- package/dist/llm/gateways/index.js.map +1 -0
- package/dist/llm/gateways/ollama.d.ts +30 -0
- package/dist/llm/gateways/ollama.d.ts.map +1 -0
- package/dist/llm/gateways/ollama.js +322 -0
- package/dist/llm/gateways/ollama.js.map +1 -0
- package/dist/llm/gateways/openai-messages-adapter.d.ts +29 -0
- package/dist/llm/gateways/openai-messages-adapter.d.ts.map +1 -0
- package/dist/llm/gateways/openai-messages-adapter.js +188 -0
- package/dist/llm/gateways/openai-messages-adapter.js.map +1 -0
- package/dist/llm/gateways/openai-model-registry.d.ts +82 -0
- package/dist/llm/gateways/openai-model-registry.d.ts.map +1 -0
- package/dist/llm/gateways/openai-model-registry.js +352 -0
- package/dist/llm/gateways/openai-model-registry.js.map +1 -0
- package/dist/llm/gateways/openai.d.ts +40 -0
- package/dist/llm/gateways/openai.d.ts.map +1 -0
- package/dist/llm/gateways/openai.js +469 -0
- package/dist/llm/gateways/openai.js.map +1 -0
- package/dist/llm/gateways/tokenizerGateway.d.ts +61 -0
- package/dist/llm/gateways/tokenizerGateway.d.ts.map +1 -0
- package/dist/llm/gateways/tokenizerGateway.js +75 -0
- package/dist/llm/gateways/tokenizerGateway.js.map +1 -0
- package/dist/llm/index.d.ts +11 -0
- package/dist/llm/index.d.ts.map +1 -0
- package/dist/llm/index.js +27 -0
- package/dist/llm/index.js.map +1 -0
- package/dist/llm/models.d.ts +95 -0
- package/dist/llm/models.d.ts.map +1 -0
- package/dist/llm/models.js +50 -0
- package/dist/llm/models.js.map +1 -0
- package/dist/llm/tools/ask-user.d.ts +39 -0
- package/dist/llm/tools/ask-user.d.ts.map +1 -0
- package/dist/llm/tools/ask-user.js +111 -0
- package/dist/llm/tools/ask-user.js.map +1 -0
- package/dist/llm/tools/current-datetime.d.ts +17 -0
- package/dist/llm/tools/current-datetime.d.ts.map +1 -0
- package/dist/llm/tools/current-datetime.js +76 -0
- package/dist/llm/tools/current-datetime.js.map +1 -0
- package/dist/llm/tools/date-resolver.d.ts +17 -0
- package/dist/llm/tools/date-resolver.d.ts.map +1 -0
- package/dist/llm/tools/date-resolver.js +135 -0
- package/dist/llm/tools/date-resolver.js.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/append-task.d.ts +13 -0
- package/dist/llm/tools/ephemeral-task-manager/append-task.d.ts.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/append-task.js +54 -0
- package/dist/llm/tools/ephemeral-task-manager/append-task.js.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/clear-tasks.d.ts +13 -0
- package/dist/llm/tools/ephemeral-task-manager/clear-tasks.d.ts.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/clear-tasks.js +37 -0
- package/dist/llm/tools/ephemeral-task-manager/clear-tasks.js.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/complete-task.d.ts +15 -0
- package/dist/llm/tools/ephemeral-task-manager/complete-task.d.ts.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/complete-task.js +56 -0
- package/dist/llm/tools/ephemeral-task-manager/complete-task.js.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/index.d.ts +44 -0
- package/dist/llm/tools/ephemeral-task-manager/index.d.ts.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/index.js +73 -0
- package/dist/llm/tools/ephemeral-task-manager/index.js.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/insert-task-after.d.ts +13 -0
- package/dist/llm/tools/ephemeral-task-manager/insert-task-after.d.ts.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/insert-task-after.js +59 -0
- package/dist/llm/tools/ephemeral-task-manager/insert-task-after.js.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/list-tasks.d.ts +14 -0
- package/dist/llm/tools/ephemeral-task-manager/list-tasks.d.ts.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/list-tasks.js +45 -0
- package/dist/llm/tools/ephemeral-task-manager/list-tasks.js.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/prepend-task.d.ts +13 -0
- package/dist/llm/tools/ephemeral-task-manager/prepend-task.d.ts.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/prepend-task.js +54 -0
- package/dist/llm/tools/ephemeral-task-manager/prepend-task.js.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/start-task.d.ts +15 -0
- package/dist/llm/tools/ephemeral-task-manager/start-task.d.ts.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/start-task.js +56 -0
- package/dist/llm/tools/ephemeral-task-manager/start-task.js.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/task-list.d.ts +68 -0
- package/dist/llm/tools/ephemeral-task-manager/task-list.d.ts.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/task-list.js +120 -0
- package/dist/llm/tools/ephemeral-task-manager/task-list.js.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/task.d.ts +21 -0
- package/dist/llm/tools/ephemeral-task-manager/task.d.ts.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/task.js +24 -0
- package/dist/llm/tools/ephemeral-task-manager/task.js.map +1 -0
- package/dist/llm/tools/file-manager.d.ts +127 -0
- package/dist/llm/tools/file-manager.d.ts.map +1 -0
- package/dist/llm/tools/file-manager.js +598 -0
- package/dist/llm/tools/file-manager.js.map +1 -0
- package/dist/llm/tools/index.d.ts +11 -0
- package/dist/llm/tools/index.d.ts.map +1 -0
- package/dist/llm/tools/index.js +27 -0
- package/dist/llm/tools/index.js.map +1 -0
- package/dist/llm/tools/tell-user.d.ts +31 -0
- package/dist/llm/tools/tell-user.d.ts.map +1 -0
- package/dist/llm/tools/tell-user.js +57 -0
- package/dist/llm/tools/tell-user.js.map +1 -0
- package/dist/llm/tools/tool-wrapper.d.ts +54 -0
- package/dist/llm/tools/tool-wrapper.d.ts.map +1 -0
- package/dist/llm/tools/tool-wrapper.js +91 -0
- package/dist/llm/tools/tool-wrapper.js.map +1 -0
- package/dist/llm/tools/tool.d.ts +70 -0
- package/dist/llm/tools/tool.d.ts.map +1 -0
- package/dist/llm/tools/tool.js +19 -0
- package/dist/llm/tools/tool.js.map +1 -0
- package/dist/llm/tools/web-search-tool.d.ts +35 -0
- package/dist/llm/tools/web-search-tool.d.ts.map +1 -0
- package/dist/llm/tools/web-search-tool.js +105 -0
- package/dist/llm/tools/web-search-tool.js.map +1 -0
- package/dist/llm/utils/image.d.ts +30 -0
- package/dist/llm/utils/image.d.ts.map +1 -0
- package/dist/llm/utils/image.js +65 -0
- package/dist/llm/utils/image.js.map +1 -0
- package/dist/tracer/eventStore.d.ts +101 -0
- package/dist/tracer/eventStore.d.ts.map +1 -0
- package/dist/tracer/eventStore.js +120 -0
- package/dist/tracer/eventStore.js.map +1 -0
- package/dist/tracer/index.d.ts +8 -0
- package/dist/tracer/index.d.ts.map +1 -0
- package/dist/tracer/index.js +24 -0
- package/dist/tracer/index.js.map +1 -0
- package/dist/tracer/nullTracer.d.ts +127 -0
- package/dist/tracer/nullTracer.d.ts.map +1 -0
- package/dist/tracer/nullTracer.js +148 -0
- package/dist/tracer/nullTracer.js.map +1 -0
- package/dist/tracer/tracerEvents.d.ts +209 -0
- package/dist/tracer/tracerEvents.d.ts.map +1 -0
- package/dist/tracer/tracerEvents.js +312 -0
- package/dist/tracer/tracerEvents.js.map +1 -0
- package/dist/tracer/tracerSystem.d.ts +149 -0
- package/dist/tracer/tracerSystem.d.ts.map +1 -0
- package/dist/tracer/tracerSystem.js +196 -0
- package/dist/tracer/tracerSystem.js.map +1 -0
- package/package.json +87 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summarization-agent.d.ts","sourceRoot":"","sources":["../../../src/examples/react/summarization-agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAY,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAK7C;;;;;GAKG;AACH,qBAAa,kBAAmB,YAAW,cAAc;IAM3C,OAAO,CAAC,QAAQ,CAAC,GAAG;IALhC;;;;OAIG;gBAC0B,GAAG,EAAE,SAAS;IAE3C;;;;;OAKG;IACG,iBAAiB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,KAAK,CAAC,CAAC;IAgDtE;;;;;OAKG;IACH,OAAO,CAAC,WAAW;IAWnB;;;;;OAKG;IACH,OAAO,CAAC,WAAW;CAGpB"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Summarization agent for the ReAct pattern.
|
|
4
|
+
*
|
|
5
|
+
* This agent generates the final answer based on accumulated context.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.SummarizationAgent = void 0;
|
|
9
|
+
const error_1 = require("../../error");
|
|
10
|
+
const models_1 = require("../../llm/models");
|
|
11
|
+
const formatters_1 = require("./formatters");
|
|
12
|
+
/**
|
|
13
|
+
* Agent responsible for generating the final answer.
|
|
14
|
+
*
|
|
15
|
+
* This agent reviews the context, plan, and history to synthesize
|
|
16
|
+
* a complete answer to the user's original query.
|
|
17
|
+
*/
|
|
18
|
+
class SummarizationAgent {
|
|
19
|
+
llm;
|
|
20
|
+
/**
|
|
21
|
+
* Initialize the summarization agent.
|
|
22
|
+
*
|
|
23
|
+
* @param llm - The LLM broker to use for generating summaries
|
|
24
|
+
*/
|
|
25
|
+
constructor(llm) {
|
|
26
|
+
this.llm = llm;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Generate a final answer based on the context.
|
|
30
|
+
*
|
|
31
|
+
* @param event - The finish event containing the complete context
|
|
32
|
+
* @returns Empty array (terminal event) or array with FailureOccurred on error
|
|
33
|
+
*/
|
|
34
|
+
async receiveEventAsync(event) {
|
|
35
|
+
if (event.type !== 'FinishAndSummarize') {
|
|
36
|
+
return (0, error_1.Ok)([]);
|
|
37
|
+
}
|
|
38
|
+
const finishEvent = event;
|
|
39
|
+
try {
|
|
40
|
+
const prompt = this.buildPrompt(finishEvent);
|
|
41
|
+
console.log(this.formatBlock(prompt));
|
|
42
|
+
const result = await this.llm.generate([models_1.Message.user(prompt)]);
|
|
43
|
+
if (!(0, error_1.isOk)(result)) {
|
|
44
|
+
return (0, error_1.Ok)([
|
|
45
|
+
{
|
|
46
|
+
type: 'FailureOccurred',
|
|
47
|
+
source: 'SummarizationAgent',
|
|
48
|
+
context: finishEvent.context,
|
|
49
|
+
reason: `Error during summarization: ${result.error.message}`,
|
|
50
|
+
correlationId: event.correlationId,
|
|
51
|
+
},
|
|
52
|
+
]);
|
|
53
|
+
}
|
|
54
|
+
const response = result.value;
|
|
55
|
+
console.log('\n' + '='.repeat(80));
|
|
56
|
+
console.log('FINAL ANSWER:');
|
|
57
|
+
console.log('='.repeat(80));
|
|
58
|
+
console.log(response);
|
|
59
|
+
console.log('='.repeat(80) + '\n');
|
|
60
|
+
// This is a terminal event - return empty list to stop the loop
|
|
61
|
+
return (0, error_1.Ok)([]);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
return (0, error_1.Ok)([
|
|
65
|
+
{
|
|
66
|
+
type: 'FailureOccurred',
|
|
67
|
+
source: 'SummarizationAgent',
|
|
68
|
+
context: finishEvent.context,
|
|
69
|
+
reason: `Error during summarization: ${error instanceof Error ? error.message : String(error)}`,
|
|
70
|
+
correlationId: event.correlationId,
|
|
71
|
+
},
|
|
72
|
+
]);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Generate the prompt for the summarization LLM.
|
|
77
|
+
*
|
|
78
|
+
* @param event - The finish event containing the complete context
|
|
79
|
+
* @returns The formatted prompt string
|
|
80
|
+
*/
|
|
81
|
+
buildPrompt(event) {
|
|
82
|
+
return `Based on the following context, provide a clear and concise answer to the user's query.
|
|
83
|
+
|
|
84
|
+
${(0, formatters_1.formatCurrentContext)(event.context)}
|
|
85
|
+
|
|
86
|
+
Your task:
|
|
87
|
+
Review what we've learned and provide a direct answer to: "${event.context.userQuery}"
|
|
88
|
+
|
|
89
|
+
Be specific and use the information gathered during our process.`;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Format a text block with separators for visual clarity.
|
|
93
|
+
*
|
|
94
|
+
* @param text - The text to format
|
|
95
|
+
* @returns Formatted text with separator lines
|
|
96
|
+
*/
|
|
97
|
+
formatBlock(text) {
|
|
98
|
+
return `\n${'='.repeat(80)}\n${text}\n${'='.repeat(80)}\n`;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.SummarizationAgent = SummarizationAgent;
|
|
102
|
+
//# sourceMappingURL=summarization-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summarization-agent.js","sourceRoot":"","sources":["../../../src/examples/react/summarization-agent.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAIH,uCAA+C;AAE/C,6CAA2C;AAE3C,6CAAoD;AAEpD;;;;;GAKG;AACH,MAAa,kBAAkB;IAMA;IAL7B;;;;OAIG;IACH,YAA6B,GAAc;QAAd,QAAG,GAAH,GAAG,CAAW;IAAG,CAAC;IAE/C;;;;;OAKG;IACH,KAAK,CAAC,iBAAiB,CAAC,KAAY;QAClC,IAAI,KAAK,CAAC,IAAI,KAAK,oBAAoB,EAAE,CAAC;YACxC,OAAO,IAAA,UAAE,EAAC,EAAE,CAAC,CAAC;QAChB,CAAC;QAED,MAAM,WAAW,GAAG,KAA2B,CAAC;QAEhD,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;YAC7C,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;YAEtC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,gBAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAE/D,IAAI,CAAC,IAAA,YAAI,EAAC,MAAM,CAAC,EAAE,CAAC;gBAClB,OAAO,IAAA,UAAE,EAAC;oBACR;wBACE,IAAI,EAAE,iBAAiB;wB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C;IAED;;;;;OAKG;IACK,WAAW,CAAC,IAAY;QAC9B,OAAO,KAAK,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,IAAI,KAAK,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC;IAC7D,CAAC;CACF;AAxFD,gDAwFC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Planning agent for the ReAct pattern.
|
|
3
|
+
*
|
|
4
|
+
* This agent creates structured plans for solving user queries.
|
|
5
|
+
*/
|
|
6
|
+
import { BaseAsyncAgent } from '../../agents/base-async-agent';
|
|
7
|
+
import { Event } from '../../agents/event';
|
|
8
|
+
import { Result } from '../../error';
|
|
9
|
+
import { LlmBroker } from '../../llm/broker';
|
|
10
|
+
/**
|
|
11
|
+
* Agent responsible for creating plans in the ReAct loop.
|
|
12
|
+
*
|
|
13
|
+
* This agent analyzes the user query and available tools to create
|
|
14
|
+
* a step-by-step plan for answering the query.
|
|
15
|
+
*/
|
|
16
|
+
export declare class ThinkingAgent implements BaseAsyncAgent {
|
|
17
|
+
private readonly llm;
|
|
18
|
+
private readonly tools;
|
|
19
|
+
/**
|
|
20
|
+
* Initialize the thinking agent.
|
|
21
|
+
*
|
|
22
|
+
* @param llm - The LLM broker to use for generating plans
|
|
23
|
+
*/
|
|
24
|
+
constructor(llm: LlmBroker);
|
|
25
|
+
/**
|
|
26
|
+
* Process a thinking event and generate a plan.
|
|
27
|
+
*
|
|
28
|
+
* @param event - The thinking event containing current context
|
|
29
|
+
* @returns Result containing InvokeDecisioning event with updated plan, or FailureOccurred on error
|
|
30
|
+
*/
|
|
31
|
+
receiveEventAsync(event: Event): Promise<Result<Event[], Error>>;
|
|
32
|
+
/**
|
|
33
|
+
* Generate the prompt for the planning LLM.
|
|
34
|
+
*
|
|
35
|
+
* @param event - The thinking event containing current context
|
|
36
|
+
* @returns The formatted prompt string
|
|
37
|
+
*/
|
|
38
|
+
private buildPrompt;
|
|
39
|
+
/**
|
|
40
|
+
* Format a text block with separators for visual clarity.
|
|
41
|
+
*
|
|
42
|
+
* @param text - The text to format
|
|
43
|
+
* @returns Formatted text with separator lines
|
|
44
|
+
*/
|
|
45
|
+
private formatBlock;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=thinking-agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thinking-agent.d.ts","sourceRoot":"","sources":["../../../src/examples/react/thinking-agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAM,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAQ7C;;;;;GAKG;AACH,qBAAa,aAAc,YAAW,cAAc;IAQtC,OAAO,CAAC,QAAQ,CAAC,GAAG;IAPhC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAY;IAElC;;;;OAIG;gBAC0B,GAAG,EAAE,SAAS;IAI3C;;;;;OAKG;IACG,iBAAiB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,KAAK,CAAC,CAAC;IAyEtE;;;;;OAKG;IACH,OAAO,CAAC,WAAW;IAWnB;;;;;OAKG;IACH,OAAO,CAAC,WAAW;CAGpB"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Planning agent for the ReAct pattern.
|
|
4
|
+
*
|
|
5
|
+
* This agent creates structured plans for solving user queries.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.ThinkingAgent = void 0;
|
|
9
|
+
const error_1 = require("../../error");
|
|
10
|
+
const models_1 = require("../../llm/models");
|
|
11
|
+
const date_resolver_1 = require("../../llm/tools/date-resolver");
|
|
12
|
+
const formatters_1 = require("./formatters");
|
|
13
|
+
/**
|
|
14
|
+
* Agent responsible for creating plans in the ReAct loop.
|
|
15
|
+
*
|
|
16
|
+
* This agent analyzes the user query and available tools to create
|
|
17
|
+
* a step-by-step plan for answering the query.
|
|
18
|
+
*/
|
|
19
|
+
class ThinkingAgent {
|
|
20
|
+
llm;
|
|
21
|
+
tools;
|
|
22
|
+
/**
|
|
23
|
+
* Initialize the thinking agent.
|
|
24
|
+
*
|
|
25
|
+
* @param llm - The LLM broker to use for generating plans
|
|
26
|
+
*/
|
|
27
|
+
constructor(llm) {
|
|
28
|
+
this.llm = llm;
|
|
29
|
+
this.tools = [new date_resolver_1.DateResolverTool()];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Process a thinking event and generate a plan.
|
|
33
|
+
*
|
|
34
|
+
* @param event - The thinking event containing current context
|
|
35
|
+
* @returns Result containing InvokeDecisioning event with updated plan, or FailureOccurred on error
|
|
36
|
+
*/
|
|
37
|
+
async receiveEventAsync(event) {
|
|
38
|
+
if (event.type !== 'InvokeThinking') {
|
|
39
|
+
return (0, error_1.Ok)([]);
|
|
40
|
+
}
|
|
41
|
+
const thinkingEvent = event;
|
|
42
|
+
try {
|
|
43
|
+
const prompt = this.buildPrompt(thinkingEvent);
|
|
44
|
+
console.log(this.formatBlock(prompt));
|
|
45
|
+
// Define schema for Plan object
|
|
46
|
+
const schema = {
|
|
47
|
+
type: 'object',
|
|
48
|
+
properties: {
|
|
49
|
+
steps: {
|
|
50
|
+
type: 'array',
|
|
51
|
+
items: { type: 'string' },
|
|
52
|
+
description: 'How to answer the query, step by step, each step outlining an action to take',
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
required: ['steps'],
|
|
56
|
+
};
|
|
57
|
+
const result = await this.llm.generateObject([models_1.Message.user(prompt)], schema);
|
|
58
|
+
if (!result.ok) {
|
|
59
|
+
return (0, error_1.Ok)([
|
|
60
|
+
{
|
|
61
|
+
type: 'FailureOccurred',
|
|
62
|
+
source: 'ThinkingAgent',
|
|
63
|
+
context: thinkingEvent.context,
|
|
64
|
+
reason: `Error during planning: ${result.error.message}`,
|
|
65
|
+
correlationId: event.correlationId,
|
|
66
|
+
},
|
|
67
|
+
]);
|
|
68
|
+
}
|
|
69
|
+
const plan = result.value;
|
|
70
|
+
console.log(this.formatBlock(JSON.stringify(plan, null, 2)));
|
|
71
|
+
// Update context with new plan
|
|
72
|
+
thinkingEvent.context.plan = plan;
|
|
73
|
+
// Add planning step to history
|
|
74
|
+
thinkingEvent.context.history.push({
|
|
75
|
+
thought: 'I need to create a plan to solve this query.',
|
|
76
|
+
action: 'Created a step-by-step plan.',
|
|
77
|
+
observation: `Plan has ${plan.steps.length} steps.`,
|
|
78
|
+
});
|
|
79
|
+
return (0, error_1.Ok)([
|
|
80
|
+
{
|
|
81
|
+
type: 'InvokeDecisioning',
|
|
82
|
+
source: 'ThinkingAgent',
|
|
83
|
+
context: thinkingEvent.context,
|
|
84
|
+
correlationId: event.correlationId,
|
|
85
|
+
},
|
|
86
|
+
]);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
return (0, error_1.Ok)([
|
|
90
|
+
{
|
|
91
|
+
type: 'FailureOccurred',
|
|
92
|
+
source: 'ThinkingAgent',
|
|
93
|
+
context: thinkingEvent.context,
|
|
94
|
+
reason: `Error during planning: ${error instanceof Error ? error.message : String(error)}`,
|
|
95
|
+
correlationId: event.correlationId,
|
|
96
|
+
},
|
|
97
|
+
]);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Generate the prompt for the planning LLM.
|
|
102
|
+
*
|
|
103
|
+
* @param event - The thinking event containing current context
|
|
104
|
+
* @returns The formatted prompt string
|
|
105
|
+
*/
|
|
106
|
+
buildPrompt(event) {
|
|
107
|
+
return `You are to solve a problem by reasoning and acting on the information you have. Here is the current context:
|
|
108
|
+
|
|
109
|
+
${(0, formatters_1.formatCurrentContext)(event.context)}
|
|
110
|
+
${(0, formatters_1.formatAvailableTools)(this.tools)}
|
|
111
|
+
|
|
112
|
+
Your Instructions:
|
|
113
|
+
Given our context and what we've done so far, and the tools available, create a step-by-step plan to answer the query.
|
|
114
|
+
Each step should be concrete and actionable. Consider which tools you'll need to use.`;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Format a text block with separators for visual clarity.
|
|
118
|
+
*
|
|
119
|
+
* @param text - The text to format
|
|
120
|
+
* @returns Formatted text with separator lines
|
|
121
|
+
*/
|
|
122
|
+
formatBlock(text) {
|
|
123
|
+
return `\n${'='.repeat(80)}\n${text}\n${'='.repeat(80)}\n`;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.ThinkingAgent = ThinkingAgent;
|
|
127
|
+
//# sourceMappingURL=thinking-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thinking-agent.js","sourceRoot":"","sources":["../../../src/examples/react/thinking-agent.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAIH,uCAAyC;AAEzC,6CAA2C;AAC3C,iEAAiE;AAGjE,6CAA0E;AAG1E;;;;;GAKG;AACH,MAAa,aAAa;IAQK;IAPZ,KAAK,CAAY;IAElC;;;;OAIG;IACH,YAA6B,GAAc;QAAd,QAAG,GAAH,GAAG,CAAW;QACzC,IAAI,CAAC,KAAK,GAAG,CAAC,IAAI,gCAAgB,EAAE,CAAC,CAAC;IACxC,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,iBAAiB,CAAC,KAAY;QAClC,IAAI,KAAK,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;YACpC,OAAO,IAAA,UAAE,EAAC,EAAE,CAAC,CAAC;QAChB,CAAC;QAED,MAAM,aAAa,GAAG,KAAuB,CAAC;QAE9C,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;YAC/C,OA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AAC,CAAC;YAE/B,OAAO,IAAA,UAAE,EAAC;gBACR;oBACE,IAAI,EAAE,mBAAmB;oBACzB,MAAM,EAAE,eAAe;oBACvB,OAAO,EAAE,aAAa,CAAC,OAAO;oBAC9B,aAAa,EAAE,KAAK,CAAC,aAAa;iBACd;aACvB,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,IAAA,UAAE,EAAC;gBACR;oBACE,IAAI,EAAE,iBAAiB;oBACvB,MAAM,EAAE,eAAe;oBACvB,OAAO,EAAE,aAAa,CAAC,OAAO;oBAC9B,MAAM,EAAE,0BAA0B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;oBAC1F,aAAa,EAAE,KAAK,CAAC,aAAa;iBAChB;aACrB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACK,WAAW,CAAC,KAAqB;QACvC,OAAO;;EAET,IAAA,iCAAoB,EAAC,KAAK,CAAC,OAAO,CAAC;EACnC,IAAA,iCAAoB,EAAC,IAAI,CAAC,KAAK,CAAC;;;;sFAIoD,CAAC;IACrF,CAAC;IAED;;;;;OAKG;IACK,WAAW,CAAC,IAAY;QAC9B,OAAO,KAAK,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,IAAI,KAAK,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC;IAC7D,CAAC;CACF;AArHD,sCAqHC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool execution agent for the ReAct pattern.
|
|
3
|
+
*
|
|
4
|
+
* This agent handles the actual execution of tools and captures the results.
|
|
5
|
+
*/
|
|
6
|
+
import { BaseAsyncAgent } from '../../agents/base-async-agent';
|
|
7
|
+
import { Event } from '../../agents/event';
|
|
8
|
+
import { Result } from '../../error';
|
|
9
|
+
/**
|
|
10
|
+
* Agent responsible for executing tool calls.
|
|
11
|
+
*
|
|
12
|
+
* This agent receives tool call events, executes the specified tool,
|
|
13
|
+
* and updates the context with the results before continuing to the
|
|
14
|
+
* decisioning phase.
|
|
15
|
+
*/
|
|
16
|
+
export declare class ToolCallAgent implements BaseAsyncAgent {
|
|
17
|
+
/**
|
|
18
|
+
* Execute a tool and update the context.
|
|
19
|
+
*
|
|
20
|
+
* @param event - The tool call event containing the tool and arguments
|
|
21
|
+
* @returns Result containing InvokeDecisioning event with updated context, or FailureOccurred on error
|
|
22
|
+
*/
|
|
23
|
+
receiveEventAsync(event: Event): Promise<Result<Event[], Error>>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=tool-call-agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-call-agent.d.ts","sourceRoot":"","sources":["../../../src/examples/react/tool-call-agent.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAY,MAAM,aAAa,CAAC;AAI/C;;;;;;GAMG;AACH,qBAAa,aAAc,YAAW,cAAc;IAClD;;;;;OAKG;IACG,iBAAiB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,KAAK,CAAC,CAAC;CAiEvE"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tool execution agent for the ReAct pattern.
|
|
4
|
+
*
|
|
5
|
+
* This agent handles the actual execution of tools and captures the results.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.ToolCallAgent = void 0;
|
|
9
|
+
const error_1 = require("../../error");
|
|
10
|
+
/**
|
|
11
|
+
* Agent responsible for executing tool calls.
|
|
12
|
+
*
|
|
13
|
+
* This agent receives tool call events, executes the specified tool,
|
|
14
|
+
* and updates the context with the results before continuing to the
|
|
15
|
+
* decisioning phase.
|
|
16
|
+
*/
|
|
17
|
+
class ToolCallAgent {
|
|
18
|
+
/**
|
|
19
|
+
* Execute a tool and update the context.
|
|
20
|
+
*
|
|
21
|
+
* @param event - The tool call event containing the tool and arguments
|
|
22
|
+
* @returns Result containing InvokeDecisioning event with updated context, or FailureOccurred on error
|
|
23
|
+
*/
|
|
24
|
+
async receiveEventAsync(event) {
|
|
25
|
+
if (event.type !== 'InvokeToolCall') {
|
|
26
|
+
return (0, error_1.Ok)([]);
|
|
27
|
+
}
|
|
28
|
+
const toolCallEvent = event;
|
|
29
|
+
try {
|
|
30
|
+
const tool = toolCallEvent.tool;
|
|
31
|
+
const toolName = tool.descriptor().function.name;
|
|
32
|
+
const args = toolCallEvent.toolArguments;
|
|
33
|
+
console.log(`\nExecuting tool: ${toolName}`);
|
|
34
|
+
console.log(`Arguments: ${JSON.stringify(args, null, 2)}`);
|
|
35
|
+
// Execute the tool
|
|
36
|
+
const result = await tool.run(args);
|
|
37
|
+
if (!(0, error_1.isOk)(result)) {
|
|
38
|
+
return (0, error_1.Ok)([
|
|
39
|
+
{
|
|
40
|
+
type: 'FailureOccurred',
|
|
41
|
+
source: 'ToolCallAgent',
|
|
42
|
+
context: toolCallEvent.context,
|
|
43
|
+
reason: `Tool execution failed: ${result.error.message}`,
|
|
44
|
+
correlationId: event.correlationId,
|
|
45
|
+
},
|
|
46
|
+
]);
|
|
47
|
+
}
|
|
48
|
+
const toolResult = result.value;
|
|
49
|
+
console.log(`Result: ${JSON.stringify(toolResult, null, 2)}`);
|
|
50
|
+
// Extract the text content from the result
|
|
51
|
+
const resultText = JSON.stringify(toolResult);
|
|
52
|
+
// Add to history
|
|
53
|
+
toolCallEvent.context.history.push({
|
|
54
|
+
thought: toolCallEvent.thought,
|
|
55
|
+
action: `Called ${toolName} with ${JSON.stringify(args)}`,
|
|
56
|
+
observation: resultText,
|
|
57
|
+
});
|
|
58
|
+
// Continue to decisioning
|
|
59
|
+
return (0, error_1.Ok)([
|
|
60
|
+
{
|
|
61
|
+
type: 'InvokeDecisioning',
|
|
62
|
+
source: 'ToolCallAgent',
|
|
63
|
+
context: toolCallEvent.context,
|
|
64
|
+
correlationId: event.correlationId,
|
|
65
|
+
},
|
|
66
|
+
]);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
console.error('Tool execution error:', error);
|
|
70
|
+
return (0, error_1.Ok)([
|
|
71
|
+
{
|
|
72
|
+
type: 'FailureOccurred',
|
|
73
|
+
source: 'ToolCallAgent',
|
|
74
|
+
context: toolCallEvent.context,
|
|
75
|
+
reason: `Tool execution failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
76
|
+
correlationId: event.correlationId,
|
|
77
|
+
},
|
|
78
|
+
]);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.ToolCallAgent = ToolCallAgent;
|
|
83
|
+
//# sourceMappingURL=tool-call-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-call-agent.js","sourceRoot":"","sources":["../../../src/examples/react/tool-call-agent.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAIH,uCAA+C;AAI/C;;;;;;GAMG;AACH,MAAa,aAAa;IACxB;;;;;OAKG;IACH,KAAK,CAAC,iBAAiB,CAAC,KAAY;QAClC,IAAI,KAAK,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;YACpC,OAAO,IAAA,UAAE,EAAC,EAAE,CAAC,CAAC;QAChB,CAAC;QAED,MAAM,aAAa,GAAG,KAAuB,CAAC;QAE9C,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC;YAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC;YACjD,MAAM,IAAI,G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AC,OAAO;oBAC9B,aAAa,EAAE,KAAK,CAAC,aAAa;iBACd;aACvB,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,KAAK,CAAC,CAAC;YAC9C,OAAO,IAAA,UAAE,EAAC;gBACR;oBACE,IAAI,EAAE,iBAAiB;oBACvB,MAAM,EAAE,eAAe;oBACvB,OAAO,EAAE,aAAa,CAAC,OAAO;oBAC9B,MAAM,EAAE,0BAA0B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;oBAC1F,aAAa,EAAE,KAAK,CAAC,aAAa;iBAChB;aACrB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF;AAxED,sCAwEC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mojentic - Modern LLM integration framework for TypeScript
|
|
3
|
+
*/
|
|
4
|
+
export * from './error';
|
|
5
|
+
export * from './llm';
|
|
6
|
+
export * from './tracer';
|
|
7
|
+
export * from './agents';
|
|
8
|
+
export * from './context';
|
|
9
|
+
export declare const VERSION = "0.1.0";
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAG1B,eAAO,MAAM,OAAO,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Mojentic - Modern LLM integration framework for TypeScript
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.VERSION = void 0;
|
|
21
|
+
__exportStar(require("./error"), exports);
|
|
22
|
+
__exportStar(require("./llm"), exports);
|
|
23
|
+
__exportStar(require("./tracer"), exports);
|
|
24
|
+
__exportStar(require("./agents"), exports);
|
|
25
|
+
__exportStar(require("./context"), exports);
|
|
26
|
+
// Version
|
|
27
|
+
exports.VERSION = '0.1.0';
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;AAEH,0CAAwB;AACxB,wCAAsB;AACtB,2CAAyB;AACzB,2CAAyB;AACzB,4CAA0B;AAE1B,UAAU;AACG,QAAA,OAAO,GAAG,OAAO,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent - Simple agent with LLM broker, tools, and behavior
|
|
3
|
+
*/
|
|
4
|
+
import { LlmBroker } from './broker';
|
|
5
|
+
import { LlmTool } from './tools';
|
|
6
|
+
import { LlmMessage } from './models';
|
|
7
|
+
import { Result } from '../error';
|
|
8
|
+
/**
|
|
9
|
+
* A simple agent that combines an LLM broker with tools and behavior.
|
|
10
|
+
* Agents can be composed and used as tools by other agents through ToolWrapper.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const agent = new Agent(
|
|
15
|
+
* new LlmBroker('qwen3:32b', gateway),
|
|
16
|
+
* [new DateResolverTool()],
|
|
17
|
+
* 'You are a helpful assistant that can resolve dates.'
|
|
18
|
+
* );
|
|
19
|
+
*
|
|
20
|
+
* const result = await agent.generate('What day is next Friday?');
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare class Agent {
|
|
24
|
+
private readonly broker;
|
|
25
|
+
private readonly tools;
|
|
26
|
+
private readonly behavior;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new agent instance.
|
|
29
|
+
*
|
|
30
|
+
* @param broker - The LLM broker to use for generation
|
|
31
|
+
* @param tools - Array of tools available to the agent
|
|
32
|
+
* @param behavior - System message defining agent's personality and behavior
|
|
33
|
+
*/
|
|
34
|
+
constructor(broker: LlmBroker, tools?: LlmTool[], behavior?: string);
|
|
35
|
+
/**
|
|
36
|
+
* Generate a response to user input.
|
|
37
|
+
*
|
|
38
|
+
* @param input - User input string
|
|
39
|
+
* @returns Result containing the agent's response or an error
|
|
40
|
+
*/
|
|
41
|
+
generate(input: string): Promise<Result<string, Error>>;
|
|
42
|
+
/**
|
|
43
|
+
* Create initial messages with system behavior.
|
|
44
|
+
* Can be used by ToolWrapper to set up agent context.
|
|
45
|
+
*
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
createInitialMessages(): LlmMessage[];
|
|
49
|
+
/**
|
|
50
|
+
* Get the agent's broker.
|
|
51
|
+
*
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
getBroker(): LlmBroker;
|
|
55
|
+
/**
|
|
56
|
+
* Get the agent's tools.
|
|
57
|
+
*
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
getTools(): LlmTool[];
|
|
61
|
+
/**
|
|
62
|
+
* Get the agent's behavior.
|
|
63
|
+
*
|
|
64
|
+
* @internal
|
|
65
|
+
*/
|
|
66
|
+
getBehavior(): string;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/llm/agent.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAW,UAAU,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;;;;;;;;;;;;;GAcG;AACH,qBAAa,KAAK;IASd,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAV3B;;;;;;OAMG;gBAEgB,MAAM,EAAE,SAAS,EACjB,KAAK,GAAE,OAAO,EAAO,EACrB,QAAQ,GAAE,MAAuC;IAGpE;;;;;OAKG;IACG,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAM7D;;;;;OAKG;IACH,qBAAqB,IAAI,UAAU,EAAE;IAIrC;;;;OAIG;IACH,SAAS,IAAI,SAAS;IAItB;;;;OAIG;IACH,QAAQ,IAAI,OAAO,EAAE;IAIrB;;;;OAIG;IACH,WAAW,IAAI,MAAM;CAGtB"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Agent - Simple agent with LLM broker, tools, and behavior
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Agent = void 0;
|
|
7
|
+
const models_1 = require("./models");
|
|
8
|
+
/**
|
|
9
|
+
* A simple agent that combines an LLM broker with tools and behavior.
|
|
10
|
+
* Agents can be composed and used as tools by other agents through ToolWrapper.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const agent = new Agent(
|
|
15
|
+
* new LlmBroker('qwen3:32b', gateway),
|
|
16
|
+
* [new DateResolverTool()],
|
|
17
|
+
* 'You are a helpful assistant that can resolve dates.'
|
|
18
|
+
* );
|
|
19
|
+
*
|
|
20
|
+
* const result = await agent.generate('What day is next Friday?');
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
class Agent {
|
|
24
|
+
broker;
|
|
25
|
+
tools;
|
|
26
|
+
behavior;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new agent instance.
|
|
29
|
+
*
|
|
30
|
+
* @param broker - The LLM broker to use for generation
|
|
31
|
+
* @param tools - Array of tools available to the agent
|
|
32
|
+
* @param behavior - System message defining agent's personality and behavior
|
|
33
|
+
*/
|
|
34
|
+
constructor(broker, tools = [], behavior = 'You are a helpful assistant.') {
|
|
35
|
+
this.broker = broker;
|
|
36
|
+
this.tools = tools;
|
|
37
|
+
this.behavior = behavior;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Generate a response to user input.
|
|
41
|
+
*
|
|
42
|
+
* @param input - User input string
|
|
43
|
+
* @returns Result containing the agent's response or an error
|
|
44
|
+
*/
|
|
45
|
+
async generate(input) {
|
|
46
|
+
const messages = this.createInitialMessages();
|
|
47
|
+
messages.push(models_1.Message.user(input));
|
|
48
|
+
return this.broker.generate(messages, this.tools);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Create initial messages with system behavior.
|
|
52
|
+
* Can be used by ToolWrapper to set up agent context.
|
|
53
|
+
*
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
createInitialMessages() {
|
|
57
|
+
return [models_1.Message.system(this.behavior)];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get the agent's broker.
|
|
61
|
+
*
|
|
62
|
+
* @internal
|
|
63
|
+
*/
|
|
64
|
+
getBroker() {
|
|
65
|
+
return this.broker;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Get the agent's tools.
|
|
69
|
+
*
|
|
70
|
+
* @internal
|
|
71
|
+
*/
|
|
72
|
+
getTools() {
|
|
73
|
+
return this.tools;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get the agent's behavior.
|
|
77
|
+
*
|
|
78
|
+
* @internal
|
|
79
|
+
*/
|
|
80
|
+
getBehavior() {
|
|
81
|
+
return this.behavior;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.Agent = Agent;
|
|
85
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/llm/agent.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAIH,qCAA+C;AAG/C;;;;;;;;;;;;;;GAcG;AACH,MAAa,KAAK;IASG;IACA;IACA;IAVnB;;;;;;OAMG;IACH,YACmB,MAAiB,EACjB,QAAmB,EAAE,EACrB,WAAmB,8BAA8B;QAFjD,WAAM,GAAN,MAAM,CAAW;QACjB,UAAK,GAAL,KAAK,CAAgB;QACrB,aAAQ,GAAR,QAAQ,CAAyC;IACjE,CAAC;IAEJ;;;;;OAKG;IACH,KAAK,CAAC,QAAQ,CAAC,KAAa;QAC1B,MAAM,QAAQ,GAAG,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC9C,QAAQ,CAAC,IAAI,CAAC,gBAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QACnC,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IACpD,CAAC;IAED;;;;;OAKG;IACH,qBAAqB;QACnB,OAAO,CAAC,gBAAO,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IACzC,CAAC;IAED;;;;OAIG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;;;OAIG;IACH,WAAW;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF;AA9DD,sBA8DC"}
|