Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Fix anthropic tests

haxziedcdc83691b5b
diff --git a/examples/anthropic/src/index.ts b/examples/anthropic/src/index.ts
index 6f9289c1c..30446013e 100644
--- a/examples/anthropic/src/index.ts
+++ b/examples/anthropic/src/index.ts
@@ -19,7 +19,7 @@ const anthropic = new Anthropic({
*/
const composio = new Composio({
apiKey: process.env.COMPOSIO_API_KEY,
- provider: new AnthropicProvider(),
+ provider: new AnthropicProvider({ cacheTools: true }),
});
async function main() {
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index a920ab95c..9b9ab0ccc 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -12,7 +12,7 @@ export type { Provider, ExecuteToolFn, ExecuteToolFnOptions } from './types/prov
export type { ExecuteMetadata } from './types/customTool.types';
export { AuthConfigTypes, AuthSchemeTypes } from './types/authConfigs.types';
export type { AuthConfigType, AuthSchemeType } from './types/authConfigs.types';
-
+export { default as logger } from './utils/logger';
// Error handling exports
export * from './errors';
diff --git a/packages/core/src/types/tool.types.ts b/packages/core/src/types/tool.types.ts
index 5f481d44e..eb97f48a2 100644
--- a/packages/core/src/types/tool.types.ts
+++ b/packages/core/src/types/tool.types.ts
@@ -13,6 +13,38 @@ export const ToolkitSchema = z.object({
});
export type Toolkit = z.infer<typeof ToolkitSchema>;
+// JSON Schema primitive types
+const JSONSchemaType = z.enum([
+ 'string',
+ 'number',
+ 'integer',
+ 'boolean',
+ 'object',
+ 'array',
+ 'null',
+]);
+
+// JSON Schema property definition
+const JSONSchemaProperty: z.ZodType<unknown> = z.object({
+ type: JSONSchemaType.optional(),
+ description: z.string().optional(),
+ title: z.string().optional(),
+ default: z.any().optional(),
+ properties: z.lazy(() => z.record(z.string(), JSONSchemaProperty)).optional(),
+ required: z.array(z.string()).optional(),
+ items: z.lazy(() => JSONSchemaProperty).optional(),
+});
+
+// Schema for parameters (input/output)
+const ParametersSchema = z.object({
+ type: z.literal('object'),
+ properties: z.record(z.string(), JSONSchemaProperty),
+ required: z.array(z.string()).optional(),
+ title: z.string().optional(),
+ description: z.string().optional(),
+ additionalProperties: z.boolean().optional(),
+});
+
/**
* Tool is a single action that can be performed by a toolkit.
* Tool is simlar to an action that an app can perform.
@@ -23,14 +55,8 @@ export const ToolSchema = z.object({
slug: z.string().describe('The slug of the tool. eg. "GOOGLE_SEARCH"'),
name: z.string().describe(`The name of the tool. eg. "Google Search"`),
description: z.string().optional().describe('The description of the tool'),
- inputParameters: z
- .record(z.string(), z.unknown())
- .optional()
- .describe('The input parameters of the tool'),
- outputParameters: z
- .record(z.string(), z.unknown())
- .optional()
- .describe('The output parameters of the tool'),
+ inputParameters: ParametersSchema.optional().describe('The input parameters of the tool'),
+ outputParameters: ParametersSchema.optional().describe('The output parameters of the tool'),
tags: z.optional(z.array(z.string())).describe('The tags of the tool. eg: Important').default([]),
toolkit: z.optional(ToolkitSchema).describe('The toolkit of the tool'),
version: z.optional(z.string()).describe('The version of the tool, e.g. "1.0.0"'),
diff --git a/packages/providers/anthropic/src/index.ts b/packages/providers/anthropic/src/index.ts
index 6a019d63e..d68f1715c 100644
--- a/packages/providers/anthropic/src/index.ts
+++ b/packages/providers/anthropic/src/index.ts
@@ -13,9 +13,10 @@ import {
ExecuteToolModifiers,
ExecuteToolFnOptions,
ToolExecuteParams,
+ logger,
} from '@composio/core';
import Anthropic from '@anthropic-ai/sdk';
-import { AnthropicTool } from './types';
+import { AnthropicTool, InputSchema } from './types';
/**
* Collection of Anthropic tools
@@ -48,6 +49,13 @@ export class AnthropicProvider extends BaseNonAgenticProvider<
AnthropicTool
> {
readonly name = 'anthropic';
+ private chacheTools: boolean = false;
+
+ constructor(options?: { cacheTools?: boolean }) {
+ super();
+ this.chacheTools = options?.cacheTools ?? false;
+ logger.debug(`AnthropicProvider initialized [cacheTools: ${this.chacheTools}]`);
+ }
/**
* Wrap a tool in the Anthropic format.
@@ -58,11 +66,12 @@ export class AnthropicProvider extends BaseNonAgenticProvider<
return {
name: tool.slug,
description: tool.description || '',
- input_schema: {
+ input_schema: (tool.inputParameters || {
type: 'object',
- properties: (tool.inputParameters?.properties || {}) as Record<string, unknown>,
- required: (tool.inputParameters?.required || []) as string[],
- },
+ properties: {},
+ required: [],
+ }) as InputSchema,
+ cache_control: this.chacheTools ? { type: 'ephemeral' } : undefined,
};
}
diff --git a/packages/providers/anthropic/test/anthropic.test.ts b/packages/providers/anthropic/test/anthropic.test.ts
index 7ca3af2b9..ae9778566 100644
--- a/packages/providers/anthropic/test/anthropic.test.ts
+++ b/packages/providers/anthropic/test/anthropic.test.ts
@@ -1,6 +1,7 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
-import { AnthropicProvider, AnthropicTool, AnthropicToolUseBlock } from '../src';
-import { Tool } from '@composio/core';
+import { AnthropicProvider, AnthropicToolUseBlock } from '../src';
+import type { AnthropicTool } from '../src/types';
+import type { Tool } from '@composio/core';
import Anthropic from '@anthropic-ai/sdk';
vi.mock('@anthropic-ai/sdk', () => {
@@ -168,9 +169,7 @@ describe('AnthropicProvider', () => {
},
undefined
);
- expect(result).toBe(
- JSON.stringify({ result: 'success' })
- );
+ expect(result).toBe(JSON.stringify({ result: 'success' }));
});
it('should pass options to executeTool', async () => {
@@ -307,9 +306,7 @@ describe('AnthropicProvider', () => {
const userId = 'test-user';
const message = {
id: 'msg_123',
- content: [
- { type: 'text', text: 'Hello' },
- ],
+ content: [{ type: 'text', text: 'Hello' }],
} as Anthropic.Message;
const executeToolCallSpy = vi.spyOn(provider, 'executeToolCall');
diff --git a/packages/providers/vercel/src/index.ts b/packages/providers/vercel/src/index.ts
index 2a5cbb256..db634cc94 100644
--- a/packages/providers/vercel/src/index.ts
+++ b/packages/providers/vercel/src/index.ts
@@ -26,7 +26,7 @@ export class VercelProvider extends BaseAgenticProvider<VercelToolCollection, Ve
wrapTool(composioTool: ComposioTool, executeTool: ExecuteToolFn): VercelTool {
return tool({
description: composioTool.description,
- parameters: jsonSchema(composioTool.inputParameters ?? {}),
+ parameters: jsonSchema((composioTool.inputParameters as Record<string, unknown>) ?? {}),
execute: async params => {
const input = typeof params === 'string' ? JSON.parse(params) : params;
return await executeTool(composioTool.slug, input);