Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 23, 01:45 UTC
Fix anthropic tests
haxzie committed
May 28, 2025 at 13:04 UTC
dcdc83691b5bff8410f4676cf43b978e81932d26
6 files changed
+56
-24
examples/anthropic/src/index.ts
+1
-1
@@ -19,7 +19,7 @@ const anthropic = new Anthropic({
19
*/
20
const composio = new Composio({
21
apiKey: process.env.COMPOSIO_API_KEY,
22
- provider: new AnthropicProvider(),
22
+ provider: new AnthropicProvider({ cacheTools: true }),
23
});
24
25
async function main() {
packages/core/src/index.ts
+1
-1
@@ -12,7 +12,7 @@ export type { Provider, ExecuteToolFn, ExecuteToolFnOptions } from './types/prov
12
export type { ExecuteMetadata } from './types/customTool.types';
13
export { AuthConfigTypes, AuthSchemeTypes } from './types/authConfigs.types';
14
export type { AuthConfigType, AuthSchemeType } from './types/authConfigs.types';
15
-
15
+export { default as logger } from './utils/logger';
16
// Error handling exports
17
export * from './errors';
18
packages/core/src/types/tool.types.ts
+34
-8
@@ -13,6 +13,38 @@ export const ToolkitSchema = z.object({
13
});
14
export type Toolkit = z.infer<typeof ToolkitSchema>;
15
16
+// JSON Schema primitive types
17
+const JSONSchemaType = z.enum([
18
+ 'string',
19
+ 'number',
20
+ 'integer',
21
+ 'boolean',
22
+ 'object',
23
+ 'array',
24
+ 'null',
25
+]);
26
+
27
+// JSON Schema property definition
28
+const JSONSchemaProperty: z.ZodType<unknown> = z.object({
29
+ type: JSONSchemaType.optional(),
30
+ description: z.string().optional(),
31
+ title: z.string().optional(),
32
+ default: z.any().optional(),
33
+ properties: z.lazy(() => z.record(z.string(), JSONSchemaProperty)).optional(),
34
+ required: z.array(z.string()).optional(),
35
+ items: z.lazy(() => JSONSchemaProperty).optional(),
36
+});
37
+
38
+// Schema for parameters (input/output)
39
+const ParametersSchema = z.object({
40
+ type: z.literal('object'),
41
+ properties: z.record(z.string(), JSONSchemaProperty),
42
+ required: z.array(z.string()).optional(),
43
+ title: z.string().optional(),
44
+ description: z.string().optional(),
45
+ additionalProperties: z.boolean().optional(),
46
+});
47
+
48
/**
49
* Tool is a single action that can be performed by a toolkit.
50
* Tool is simlar to an action that an app can perform.
@@ -23,14 +55,8 @@ export const ToolSchema = z.object({
55
slug: z.string().describe('The slug of the tool. eg. "GOOGLE_SEARCH"'),
56
name: z.string().describe(`The name of the tool. eg. "Google Search"`),
57
description: z.string().optional().describe('The description of the tool'),
26
- inputParameters: z
27
- .record(z.string(), z.unknown())
28
- .optional()
29
- .describe('The input parameters of the tool'),
30
- outputParameters: z
31
- .record(z.string(), z.unknown())
32
- .optional()
33
- .describe('The output parameters of the tool'),
58
+ inputParameters: ParametersSchema.optional().describe('The input parameters of the tool'),
59
+ outputParameters: ParametersSchema.optional().describe('The output parameters of the tool'),
60
tags: z.optional(z.array(z.string())).describe('The tags of the tool. eg: Important').default([]),
61
toolkit: z.optional(ToolkitSchema).describe('The toolkit of the tool'),
62
version: z.optional(z.string()).describe('The version of the tool, e.g. "1.0.0"'),
packages/providers/anthropic/src/index.ts
+14
-5
@@ -13,9 +13,10 @@ import {
13
ExecuteToolModifiers,
14
ExecuteToolFnOptions,
15
ToolExecuteParams,
16
+ logger,
17
} from '@composio/core';
18
import Anthropic from '@anthropic-ai/sdk';
18
-import { AnthropicTool } from './types';
19
+import { AnthropicTool, InputSchema } from './types';
20
21
/**
22
* Collection of Anthropic tools
@@ -48,6 +49,13 @@ export class AnthropicProvider extends BaseNonAgenticProvider<
49
AnthropicTool
50
> {
51
readonly name = 'anthropic';
52
+ private chacheTools: boolean = false;
53
+
54
+ constructor(options?: { cacheTools?: boolean }) {
55
+ super();
56
+ this.chacheTools = options?.cacheTools ?? false;
57
+ logger.debug(`AnthropicProvider initialized [cacheTools: ${this.chacheTools}]`);
58
+ }
59
60
/**
61
* Wrap a tool in the Anthropic format.
@@ -58,11 +66,12 @@ export class AnthropicProvider extends BaseNonAgenticProvider<
66
return {
67
name: tool.slug,
68
description: tool.description || '',
61
- input_schema: {
69
+ input_schema: (tool.inputParameters || {
70
type: 'object',
63
- properties: (tool.inputParameters?.properties || {}) as Record<string, unknown>,
64
- required: (tool.inputParameters?.required || []) as string[],
65
- },
71
+ properties: {},
72
+ required: [],
73
+ }) as InputSchema,
74
+ cache_control: this.chacheTools ? { type: 'ephemeral' } : undefined,
75
};
76
}
77
packages/providers/anthropic/test/anthropic.test.ts
+5
-8
@@ -1,6 +1,7 @@
1
import { describe, it, expect, vi, beforeEach } from 'vitest';
2
-import { AnthropicProvider, AnthropicTool, AnthropicToolUseBlock } from '../src';
3
-import { Tool } from '@composio/core';
2
+import { AnthropicProvider, AnthropicToolUseBlock } from '../src';
3
+import type { AnthropicTool } from '../src/types';
4
+import type { Tool } from '@composio/core';
5
import Anthropic from '@anthropic-ai/sdk';
6
7
vi.mock('@anthropic-ai/sdk', () => {
@@ -168,9 +169,7 @@ describe('AnthropicProvider', () => {
169
},
170
undefined
171
);
171
- expect(result).toBe(
172
- JSON.stringify({ result: 'success' })
173
- );
172
+ expect(result).toBe(JSON.stringify({ result: 'success' }));
173
});
174
175
it('should pass options to executeTool', async () => {
@@ -307,9 +306,7 @@ describe('AnthropicProvider', () => {
306
const userId = 'test-user';
307
const message = {
308
id: 'msg_123',
310
- content: [
311
- { type: 'text', text: 'Hello' },
312
- ],
309
+ content: [{ type: 'text', text: 'Hello' }],
310
} as Anthropic.Message;
311
312
const executeToolCallSpy = vi.spyOn(provider, 'executeToolCall');
packages/providers/vercel/src/index.ts
+1
-1
@@ -26,7 +26,7 @@ export class VercelProvider extends BaseAgenticProvider<VercelToolCollection, Ve
26
wrapTool(composioTool: ComposioTool, executeTool: ExecuteToolFn): VercelTool {
27
return tool({
28
description: composioTool.description,
29
- parameters: jsonSchema(composioTool.inputParameters ?? {}),
29
+ parameters: jsonSchema((composioTool.inputParameters as Record<string, unknown>) ?? {}),
30
execute: async params => {
31
const input = typeof params === 'string' ? JSON.parse(params) : params;
32
return await executeTool(composioTool.slug, input);