agent-swarm-kit 1.1.72 → 1.1.74
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/README.md +3 -3
- package/build/index.cjs +56 -0
- package/build/index.mjs +56 -0
- package/package.json +1 -1
- package/types.d.ts +7 -0
package/README.md
CHANGED
|
@@ -417,9 +417,7 @@ P.S. [openai threads](https://platform.openai.com/docs/api-reference/threads) do
|
|
|
417
417
|
|
|
418
418
|
## 🔌 Tool and System Prompt Reflection
|
|
419
419
|
|
|
420
|
-
Enhance your LLMs with flexible, runtime-configurable tools and system prompts using `agent-swarm-kit`. The library allows you to define tools with dynamic interfaces, enabling agents to adapt their functionality based on context or agent-specific requirements. This makes it easy to integrate specialized capabilities, like fetching real-time data or generating reports, with minimal boilerplate.
|
|
421
|
-
|
|
422
|
-
**Example**: Below is a tool that dynamically fetches short-range EMA (Exponential Moving Average) signals for a trading agent, with a description tailored to the agent's display name:
|
|
420
|
+
Enhance your LLMs with flexible, runtime-configurable tools and system prompts using `agent-swarm-kit`. The library allows you to define tools with dynamic interfaces, enabling agents to adapt their functionality based on context or agent-specific requirements. This makes it easy to integrate specialized capabilities, like fetching real-time data or generating reports without additional tool arguments, with minimal boilerplate. 🛠️
|
|
423
421
|
|
|
424
422
|
```tsx
|
|
425
423
|
addTool({
|
|
@@ -449,6 +447,8 @@ addTool({
|
|
|
449
447
|
});
|
|
450
448
|
```
|
|
451
449
|
|
|
450
|
+
**Example**: Below is a tool that dynamically fetches short-range EMA (Exponential Moving Average) signals for a trading agent, with a description tailored to the agent's display name 🌐
|
|
451
|
+
|
|
452
452
|
---
|
|
453
453
|
|
|
454
454
|
## ✅ Tested & Reliable
|
package/build/index.cjs
CHANGED
|
@@ -24072,6 +24072,62 @@ const RETRY_DELAY = 5000;
|
|
|
24072
24072
|
*/
|
|
24073
24073
|
class AdapterUtils {
|
|
24074
24074
|
constructor() {
|
|
24075
|
+
/**
|
|
24076
|
+
* Creates a function to interact with Grok's chat completions API.
|
|
24077
|
+
* @param {any} grok - The Grok client instance.
|
|
24078
|
+
* @param {string} [model="grok-3-mini"] - The model to use for completions (defaults to "grok-3-mini").
|
|
24079
|
+
* @returns {TCompleteFn} A function that processes completion arguments and returns a response from Grok.
|
|
24080
|
+
*/
|
|
24081
|
+
this.fromGrok = (grok, model = "grok-3-mini") =>
|
|
24082
|
+
/**
|
|
24083
|
+
* Handles a completion request to Grok, transforming messages and tools into the required format.
|
|
24084
|
+
* Executes requests in a pool to limit concurrency with retry logic for reliability.
|
|
24085
|
+
* @param {ICompletionArgs} args - The arguments for the completion request.
|
|
24086
|
+
* @param {string} args.agentName - The name of the agent making the request.
|
|
24087
|
+
* @param {IModelMessage[]} args.messages - The array of messages to send to Grok.
|
|
24088
|
+
* @param {string} args.mode - The mode of the completion (e.g., "user" or "tool").
|
|
24089
|
+
* @param {any[]} args.tools - The tools available for the completion, if any.
|
|
24090
|
+
* @returns {Promise<IModelMessage>} The response from Grok in `agent-swarm-kit` format.
|
|
24091
|
+
*/
|
|
24092
|
+
functoolsKit.execpool(functoolsKit.retry(async ({ agentName, messages: rawMessages, mode, tools, clientId, }) => {
|
|
24093
|
+
LoggerAdapter.logClient(clientId, "AdapterUtils fromGrok completion", JSON.stringify(rawMessages));
|
|
24094
|
+
const messages = rawMessages.map(({ role, tool_call_id, tool_calls, content }) => ({
|
|
24095
|
+
role,
|
|
24096
|
+
tool_call_id,
|
|
24097
|
+
content,
|
|
24098
|
+
tool_calls: tool_calls?.map(({ function: f, ...rest }) => ({
|
|
24099
|
+
...rest,
|
|
24100
|
+
function: {
|
|
24101
|
+
name: f.name,
|
|
24102
|
+
arguments: JSON.stringify(f.arguments),
|
|
24103
|
+
},
|
|
24104
|
+
})),
|
|
24105
|
+
}));
|
|
24106
|
+
const { choices: [{ message: { content, role, tool_calls }, },], } = await grok.chat.completions.create({
|
|
24107
|
+
model,
|
|
24108
|
+
messages: messages,
|
|
24109
|
+
tools: tools,
|
|
24110
|
+
response_format: {
|
|
24111
|
+
type: "text",
|
|
24112
|
+
},
|
|
24113
|
+
});
|
|
24114
|
+
return {
|
|
24115
|
+
content: content,
|
|
24116
|
+
mode,
|
|
24117
|
+
agentName,
|
|
24118
|
+
role,
|
|
24119
|
+
tool_calls: tool_calls?.map(({ function: f, ...rest }) => ({
|
|
24120
|
+
...rest,
|
|
24121
|
+
function: {
|
|
24122
|
+
name: f.name,
|
|
24123
|
+
arguments: JSON.parse(f.arguments),
|
|
24124
|
+
},
|
|
24125
|
+
})),
|
|
24126
|
+
};
|
|
24127
|
+
}, RETRY_COUNT, RETRY_DELAY), {
|
|
24128
|
+
maxExec: EXECPOOL_SIZE,
|
|
24129
|
+
delay: EXECPOOL_WAIT,
|
|
24130
|
+
});
|
|
24075
24131
|
/**
|
|
24076
24132
|
* Creates a function to interact with CohereClientV2 chat completions API.
|
|
24077
24133
|
* @param {any} openai - The CohereClientV2 client instance.
|
package/build/index.mjs
CHANGED
|
@@ -24070,6 +24070,62 @@ const RETRY_DELAY = 5000;
|
|
|
24070
24070
|
*/
|
|
24071
24071
|
class AdapterUtils {
|
|
24072
24072
|
constructor() {
|
|
24073
|
+
/**
|
|
24074
|
+
* Creates a function to interact with Grok's chat completions API.
|
|
24075
|
+
* @param {any} grok - The Grok client instance.
|
|
24076
|
+
* @param {string} [model="grok-3-mini"] - The model to use for completions (defaults to "grok-3-mini").
|
|
24077
|
+
* @returns {TCompleteFn} A function that processes completion arguments and returns a response from Grok.
|
|
24078
|
+
*/
|
|
24079
|
+
this.fromGrok = (grok, model = "grok-3-mini") =>
|
|
24080
|
+
/**
|
|
24081
|
+
* Handles a completion request to Grok, transforming messages and tools into the required format.
|
|
24082
|
+
* Executes requests in a pool to limit concurrency with retry logic for reliability.
|
|
24083
|
+
* @param {ICompletionArgs} args - The arguments for the completion request.
|
|
24084
|
+
* @param {string} args.agentName - The name of the agent making the request.
|
|
24085
|
+
* @param {IModelMessage[]} args.messages - The array of messages to send to Grok.
|
|
24086
|
+
* @param {string} args.mode - The mode of the completion (e.g., "user" or "tool").
|
|
24087
|
+
* @param {any[]} args.tools - The tools available for the completion, if any.
|
|
24088
|
+
* @returns {Promise<IModelMessage>} The response from Grok in `agent-swarm-kit` format.
|
|
24089
|
+
*/
|
|
24090
|
+
execpool(retry(async ({ agentName, messages: rawMessages, mode, tools, clientId, }) => {
|
|
24091
|
+
LoggerAdapter.logClient(clientId, "AdapterUtils fromGrok completion", JSON.stringify(rawMessages));
|
|
24092
|
+
const messages = rawMessages.map(({ role, tool_call_id, tool_calls, content }) => ({
|
|
24093
|
+
role,
|
|
24094
|
+
tool_call_id,
|
|
24095
|
+
content,
|
|
24096
|
+
tool_calls: tool_calls?.map(({ function: f, ...rest }) => ({
|
|
24097
|
+
...rest,
|
|
24098
|
+
function: {
|
|
24099
|
+
name: f.name,
|
|
24100
|
+
arguments: JSON.stringify(f.arguments),
|
|
24101
|
+
},
|
|
24102
|
+
})),
|
|
24103
|
+
}));
|
|
24104
|
+
const { choices: [{ message: { content, role, tool_calls }, },], } = await grok.chat.completions.create({
|
|
24105
|
+
model,
|
|
24106
|
+
messages: messages,
|
|
24107
|
+
tools: tools,
|
|
24108
|
+
response_format: {
|
|
24109
|
+
type: "text",
|
|
24110
|
+
},
|
|
24111
|
+
});
|
|
24112
|
+
return {
|
|
24113
|
+
content: content,
|
|
24114
|
+
mode,
|
|
24115
|
+
agentName,
|
|
24116
|
+
role,
|
|
24117
|
+
tool_calls: tool_calls?.map(({ function: f, ...rest }) => ({
|
|
24118
|
+
...rest,
|
|
24119
|
+
function: {
|
|
24120
|
+
name: f.name,
|
|
24121
|
+
arguments: JSON.parse(f.arguments),
|
|
24122
|
+
},
|
|
24123
|
+
})),
|
|
24124
|
+
};
|
|
24125
|
+
}, RETRY_COUNT, RETRY_DELAY), {
|
|
24126
|
+
maxExec: EXECPOOL_SIZE,
|
|
24127
|
+
delay: EXECPOOL_WAIT,
|
|
24128
|
+
});
|
|
24073
24129
|
/**
|
|
24074
24130
|
* Creates a function to interact with CohereClientV2 chat completions API.
|
|
24075
24131
|
* @param {any} openai - The CohereClientV2 client instance.
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -14751,6 +14751,13 @@ type TCompleteFn = (args: ICompletionArgs) => Promise<IModelMessage>;
|
|
|
14751
14751
|
* Utility class providing adapter functions for interacting with various AI completion providers.
|
|
14752
14752
|
*/
|
|
14753
14753
|
declare class AdapterUtils {
|
|
14754
|
+
/**
|
|
14755
|
+
* Creates a function to interact with Grok's chat completions API.
|
|
14756
|
+
* @param {any} grok - The Grok client instance.
|
|
14757
|
+
* @param {string} [model="grok-3-mini"] - The model to use for completions (defaults to "grok-3-mini").
|
|
14758
|
+
* @returns {TCompleteFn} A function that processes completion arguments and returns a response from Grok.
|
|
14759
|
+
*/
|
|
14760
|
+
fromGrok: (grok: any, model?: string) => TCompleteFn;
|
|
14754
14761
|
/**
|
|
14755
14762
|
* Creates a function to interact with CohereClientV2 chat completions API.
|
|
14756
14763
|
* @param {any} openai - The CohereClientV2 client instance.
|