@covalenthq/ai-agent-sdk
Advanced tools
Comparing version 0.2.5 to 0.2.6
@@ -9,2 +9,3 @@ import type { AgentConfig, AgentName } from "."; | ||
export declare const resource_planner: (agents: Record<AgentName, Agent>) => Agent; | ||
export declare const endgame: () => Agent; | ||
export declare class Agent extends Base { | ||
@@ -11,0 +12,0 @@ private config; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Agent = exports.resource_planner = exports.router = void 0; | ||
exports.Agent = exports.endgame = exports.resource_planner = exports.router = void 0; | ||
const base_1 = require("../base"); | ||
@@ -205,2 +205,31 @@ const llm_1 = require("../llm"); | ||
exports.resource_planner = resource_planner; | ||
const endgame = () => new Agent({ | ||
name: "endgame", | ||
description: "", | ||
model: { | ||
provider: "OPEN_AI", | ||
name: "gpt-4o-mini", | ||
}, | ||
runFn: async (agent, state) => { | ||
const messages = [ | ||
(0, base_1.system)("maxIterations limit hit"), | ||
(0, base_1.user)("Please summarize all previously executed steps and do your best to achieve the main goal while responding with the final answer."), | ||
], schema = { | ||
task_result: zod_1.default.object({ | ||
final_answer: zod_1.default | ||
.string() | ||
.describe("The final result of the task"), | ||
}), | ||
}; | ||
const result = await agent.generate(messages, schema); | ||
if (!("final_answer" in result.value)) { | ||
return state_1.StateFn.finish(state, (0, base_1.assistant)("Failed to get final answer")); | ||
} | ||
if (result.type !== "task_result") { | ||
throw new Error("Expected task_result response, got " + result.type); | ||
} | ||
return state_1.StateFn.finish(state, (0, base_1.assistant)(result.value["final_answer"])); | ||
}, | ||
}); | ||
exports.endgame = endgame; | ||
class Agent extends base_1.Base { | ||
@@ -207,0 +236,0 @@ config; |
@@ -6,3 +6,3 @@ import "dotenv/config"; | ||
export type MODULE = "agent" | "llm" | "tools" | "server" | "zee"; | ||
export type AnyZodType = ZodType<any>; | ||
export type AnyZodType = ZodType<unknown>; | ||
export declare class Base { | ||
@@ -12,3 +12,3 @@ private logger; | ||
constructor(module: MODULE); | ||
info(message: string, ...args: any[]): void; | ||
info(message: string, ...args: unknown[]): void; | ||
} | ||
@@ -15,0 +15,0 @@ export declare const user: (content: string) => ChatCompletionUserMessageParam; |
@@ -34,6 +34,14 @@ "use strict"; | ||
if (state.messages.length > zeeWorkflow.maxIterations) { | ||
return state_1.StateFn.childState({ | ||
const endgameState = state_1.StateFn.childState({ | ||
...state, | ||
agent: "finalBoss", | ||
agent: "endgame", | ||
status: "running", | ||
}); | ||
const agent = zeeWorkflow.agent("endgame"); | ||
try { | ||
return await agent.run(endgameState); | ||
} | ||
catch (error) { | ||
return state_1.StateFn.finish(endgameState, (0, base_1.assistant)(error instanceof Error ? error.message : "Unknown error")); | ||
} | ||
} | ||
@@ -84,5 +92,11 @@ if (state.children.length > 0) { | ||
resource_planner: (0, agent_1.resource_planner)(options.agents), | ||
endgame: (0, agent_1.endgame)(), | ||
...options.agents, | ||
}; | ||
this.config = options; | ||
this.config = { | ||
...options, | ||
maxIterations: options.maxIterations && options.maxIterations > 0 | ||
? options.maxIterations | ||
: 50, | ||
}; | ||
} | ||
@@ -89,0 +103,0 @@ get description() { |
@@ -50,2 +50,3 @@ "use strict"; | ||
}, | ||
maxIterations: 5, | ||
}); | ||
@@ -52,0 +53,0 @@ const result = await _1.ZeeWorkflow.run(zee); |
{ | ||
"name": "@covalenthq/ai-agent-sdk", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "types": "dist/index.d.ts", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
147923
1940