| 23 | required: ['key', 'value'] |
| 24 | }, |
| 25 | async execute( |
| 26 | args: { key: string; value: string; ttl?: number }, |
| 27 | context: ToolContext |
| 28 | ): Promise<ToolResult> { |
| 29 | try { |
| 30 | // Try to parse as JSON |
| 31 | let parsedValue: any; |
| 32 | try { |
| 33 | parsedValue = JSON.parse(args.value); |
| 34 | } catch { |
| 35 | parsedValue = args.value; |
| 36 | } |
| 37 | |
| 38 | const id = sharedContext.set(args.key, parsedValue, context.agentId, args.ttl); |
| 39 | |
| 40 | return { |
| 41 | success: true, |
| 42 | data: { |
| 43 | id, |
| 44 | key: args.key, |
| 45 | stored: true |
| 46 | } |
| 47 | }; |
| 48 | } catch (error) { |
| 49 | return { |
| 50 | success: false, |
| 51 | error: error instanceof Error ? error.message : String(error) |
| 52 | }; |
| 53 | } |
| 54 | } |
| 55 | }; |
| 56 | |
| 57 | export const getSharedContextTool: Tool = { |