Skip to content

Commit afc5afb

Browse files
committed
Merge branch 'main' of arcaela:arcaelas/agent
2 parents 9103aa0 + b0534a2 commit afc5afb

12 files changed

Lines changed: 127 additions & 109 deletions

File tree

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ import { Agent, Tool } from '@arcaelas/agent';
198198
import OpenAI from 'openai';
199199

200200
// Create a simple time tool
201-
const time_tool = new Tool("get_current_time", async () => {
201+
const time_tool = new Tool("get_current_time", async (agent) => {
202202
return new Date().toLocaleString();
203203
});
204204

@@ -307,7 +307,7 @@ const weather_tool = new Tool("get_weather", {
307307
city: "City name (e.g., 'London', 'New York')",
308308
units: "Temperature units: 'celsius' or 'fahrenheit'"
309309
},
310-
func: async (params) => {
310+
func: async (agent, params) => {
311311
// Mock weather API call
312312
const temp = params.units === 'celsius' ? '22°C' : '72°F';
313313
return `Weather in ${params.city}: Sunny, ${temp}`;
@@ -402,7 +402,7 @@ const sales_context = new Context({
402402
parameters: {
403403
customer_id: "Customer ID or email address"
404404
},
405-
func: async (params) => {
405+
func: async (agent, params) => {
406406
// Mock CRM integration
407407
return `Customer ${params.customer_id}: Premium tier, active since 2023`;
408408
}
@@ -414,7 +414,7 @@ const sales_context = new Context({
414414
products: "Comma-separated list of product names",
415415
customer_tier: "Customer tier: 'standard', 'premium', or 'enterprise'"
416416
},
417-
func: async (params) => {
417+
func: async (agent, params) => {
418418
// Mock quote generation
419419
const discount = params.customer_tier === 'enterprise' ? '15%' : '5%';
420420
return `Quote generated for ${params.products} with ${discount} discount`;
@@ -592,7 +592,7 @@ const base_context = new Context({
592592
const team_context = new Context({
593593
context: base_context, // Inherits from base
594594
metadata: new Metadata().set("team", "Engineering"),
595-
tools: [new Tool("deploy", async (env) => `Deployed to ${env}`)]
595+
tools: [new Tool("deploy", async (agent, env) => `Deployed to ${env}`)]
596596
});
597597
```
598598

@@ -639,7 +639,7 @@ console.log(child_metadata.get("department")); // "Sales" (local)
639639
### Constructors
640640
```typescript
641641
// Simple tool
642-
new Tool(name: string, handler: (input: string) => any)
642+
new Tool(name: string, handler: (agent: Agent, input: string) => any)
643643

644644
// Advanced tool
645645
new Tool<T>(name: string, options: ToolOptions<T>)
@@ -650,7 +650,7 @@ new Tool<T>(name: string, options: ToolOptions<T>)
650650
interface ToolOptions<T = Record<string, string>> {
651651
description: string; // Tool functionality description
652652
parameters?: T; // Parameter schema object
653-
func: (params: T) => string | Promise<string>; // Execution function
653+
func: (agent: Agent, params: T) => string | Promise<string>; // Execution function
654654
}
655655
```
656656

@@ -663,7 +663,7 @@ interface ToolOptions<T = Record<string, string>> {
663663
### Examples
664664
```typescript
665665
// Simple tool
666-
const time_tool = new Tool("get_time", async () => {
666+
const time_tool = new Tool("get_time", async (agent) => {
667667
return new Date().toLocaleString();
668668
});
669669

@@ -674,7 +674,7 @@ const calculator = new Tool("calculate", {
674674
expression: "Mathematical expression to evaluate",
675675
precision: "Number of decimal places (optional)"
676676
},
677-
func: async (params) => {
677+
func: async (agent, params) => {
678678
const result = eval(params.expression);
679679
const precision = parseInt(params.precision) || 2;
680680
return result.toFixed(precision);
@@ -1022,7 +1022,7 @@ const optimized_providers = [
10221022
const cached_tool = new Tool("expensive_computation", {
10231023
description: "Cached computation for better performance",
10241024
parameters: { data: "Input data for processing" },
1025-
func: async (params) => {
1025+
func: async (agent, params) => {
10261026
const cache_key = `compute_${JSON.stringify(params.data)}`;
10271027
const cached_result = cache.get(cache_key);
10281028

@@ -1063,7 +1063,7 @@ const test_provider = async (ctx) => {
10631063
const debug_tool = new Tool("debug_example", {
10641064
description: "Tool with comprehensive error handling",
10651065
parameters: { input: "Test input" },
1066-
func: async (params) => {
1066+
func: async (agent, params) => {
10671067
try {
10681068
console.log("Tool input:", params);
10691069
const result = await risky_operation(params.input);

0 commit comments

Comments
 (0)