Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
Update langchain example
haxzieb9accfd69428
diff --git a/examples/langchain/package.json b/examples/langchain/package.jsonindex e6f4bb36a..5f8791cf2 100644--- a/examples/langchain/package.json+++ b/examples/langchain/package.json@@ -14,7 +14,11 @@"packageManager": "[email protected]","dependencies": {"@composio/core": "workspace:*",- "@composio/langchain": "0.1.0-rc.6",+ "@composio/langchain": "workspace:*",+ "@langchain/core": "^0.3.56",+ "@langchain/langgraph": "^0.2.72",+ "@langchain/openai": "^0.5.10",+ "dotenv": "^16.5.0","openai": "^4.94.0"},"devDependencies": {diff --git a/examples/langchain/src/index.ts b/examples/langchain/src/index.tsindex fbe8acb32..c7c84f50e 100644--- a/examples/langchain/src/index.ts+++ b/examples/langchain/src/index.ts@@ -1,16 +1,68 @@+import { ChatOpenAI } from '@langchain/openai';+import { HumanMessage, AIMessage } from '@langchain/core/messages';+import { ToolNode } from '@langchain/langgraph/prebuilt';+import { StateGraph, MessagesAnnotation } from '@langchain/langgraph';import { Composio } from '@composio/core';import { LangchainToolset } from '@composio/langchain';-import process from 'process';-+// initiate composioconst composio = new Composio({apiKey: process.env.COMPOSIO_API_KEY,toolset: new LangchainToolset(),});-// direct tool access-const tools = await composio.getTools();+// fetch the tool+const tool = await composio.tools.get('default', 'HACKERNEWS_GET_USER');++// Define the tools for the agent to use+const tools = [tool];+const toolNode = new ToolNode(tools);++// Create a model and give it access to the tools+const model = new ChatOpenAI({+ model: 'gpt-4o-mini',+ temperature: 0,+}).bindTools(tools);++// Define the function that determines whether to continue or not+function shouldContinue({ messages }: typeof MessagesAnnotation.State) {+ const lastMessage = messages[messages.length - 1] as AIMessage;++ // If the LLM makes a tool call, then we route to the "tools" node+ if (lastMessage.tool_calls?.length) {+ return 'tools';+ }+ // Otherwise, we stop (reply to the user) using the special "__end__" node+ return '__end__';+}-console.log(tools);+// Define the function that calls the model+async function callModel(state: typeof MessagesAnnotation.State) {+ const response = await model.invoke(state.messages);+ // We return a list, because this will get added to the existing list+ return { messages: [response] };+}+// Define a new graph+const workflow = new StateGraph(MessagesAnnotation)+ .addNode('agent', callModel)+ .addEdge('__start__', 'agent') // __start__ is a special name for the entrypoint+ .addNode('tools', toolNode)+ .addEdge('tools', 'agent')+ .addConditionalEdges('agent', shouldContinue);+// Finally, we compile it into a LangChain Runnable.+const app = workflow.compile();++// Use the agent+const finalState = await app.invoke({+ messages: [new HumanMessage('Find the details of the user `pg` on HackerNews')],+});+console.log(finalState.messages[finalState.messages.length - 1].content);++const nextState = await app.invoke({+ // Including the messages from the previous run gives the LLM context.+ // This way it knows we're asking about the weather in NY+ messages: [...finalState.messages, new HumanMessage('what about haxzie')],+});+console.log(nextState.messages[nextState.messages.length - 1].content);diff --git a/examples/openai/src/examples.ts b/examples/openai/src/examples.tsdeleted file mode 100644index df6c59203..000000000--- a/examples/openai/src/examples.ts+++ /dev/null@@ -1,38 +0,0 @@-/**- * Basic Composio Tool Fetching Example- *- * This example demonstrates how to fetch a tool from Composio.- * It retrieves the HACKERNEWS_GET_USER tool and logs its schema.- */-import { Composio } from '@composio/core';-import dotenv from 'dotenv';--dotenv.config();--const composio = new Composio({- apiKey: process.env.COMPOSIO_API_KEY,-});--/**- * Main function to demonstrate fetching a tool from Composio- */-async function main() {- try {- console.log('Fetching HACKERNEWS_GET_USER tool...');- const tool = await composio.getToolBySlug('default', 'HACKERNEWS_GET_USER');-- console.log('Tool details:');- console.log(JSON.stringify(tool, null, 2));-- console.log('\nInput parameters:');- if (tool.function.parameters.properties) {- for (const [key, value] of Object.entries(tool.function.parameters.properties)) {- console.log(`- ${key}: ${JSON.stringify(value)}`);- }- }- } catch (error) {- console.error('Error fetching tool:', error);- }-}--main();diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex bc3f62e8e..c5fe1d836 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -64,8 +64,20 @@ importers:specifier: workspace:*version: link:../../packages/core'@composio/langchain':- specifier: 0.1.0-rc.6+ specifier: workspace:*+ version: link:../../packages/toolsets/langchain+ '@langchain/core':+ specifier: ^0.3.56+ '@langchain/langgraph':+ specifier: ^0.2.72+ version: 0.2.72(@langchain/[email protected]([email protected]([email protected])([email protected])))([email protected])([email protected]([email protected]))+ '@langchain/openai':+ specifier: ^0.5.10+ version: 0.5.10(@langchain/[email protected]([email protected]([email protected])([email protected])))([email protected])+ dotenv:+ specifier: ^16.5.0+ version: 16.5.0openai:specifier: ^4.94.0version: 4.98.0([email protected])([email protected])@@ -289,12 +301,6 @@ packages:'@composio/[email protected]':resolution: {integrity: sha512-uhXW5NxIY+j5IZ7WnzOLrVmOAhSCb1FdQbvDxPCcQqpE7d78uRHS9i/aK4Xn6UNIPv+pt1BT8unR0zEdKjG3Ng==}- '@composio/[email protected]':- resolution: {integrity: sha512-kSkkTjxJGUVABbVThsMXiNiIPZy0qNku77lG3wgDcFMGps7OLrL1vTT0t19cCL3Jl4jwJQm5qROpgCBQveFCbA==}-- '@composio/[email protected]':- resolution: {integrity: sha512-nx/emBOfyltoK1TeGXdqLnwSvirZW3u+Bs0cOkwMnT+zE9FDeX1sfVgl91SrhLqSWQLcaa/mAb6MRQ9LxYv2CA==}-'@emnapi/[email protected]':resolution: {integrity: sha512-4m62DuCE07lw01soJwPiBGC0nAww0Q+RY70VZ+n49yDIO13yyinhbWCeNnaob0lakDtWQzSdtNWzJeOJt2ma+g==}@@ -549,6 +555,39 @@ packages:resolution: {integrity: sha512-eF9MyInM9RLNisAygiCrzHnqzOnuzGWy4f1SAqAis+XIMhcA98WuZDNWxyX9pP3aKQGc47FAJ/9XWJwv5KiquA==}engines: {node: '>=18'}+ '@langchain/[email protected]':+ resolution: {integrity: sha512-6b3CuVVYx+7x0uWLG+7YXz9j2iBa+tn2AXvkLxzEvaAsLE6Sij++8PPbS2BZzC+S/FPJdWsz6I5bsrqL0BYrCA==}+ engines: {node: '>=18'}+ peerDependencies:+ '@langchain/core': '>=0.2.31 <0.4.0'++ '@langchain/[email protected]':+ resolution: {integrity: sha512-IUN0m4BYkGWdviFd4EaWDcQgxNq8z+1LIwXajCSt9B+Cb/pz0ZNpIPdu5hAIsf6a0RWu5yRUhzL1L40t7vu3Zg==}+ peerDependencies:+ '@langchain/core': '>=0.2.31 <0.4.0'+ react: ^18 || ^19+ peerDependenciesMeta:+ '@langchain/core':+ optional: true+ react:+ optional: true++ '@langchain/[email protected]':+ resolution: {integrity: sha512-2Rs79mLSx0Yxr/omiWOXBlaS+eywZ9KACe06pI6XkA3hT2hwqjMlXYMvbeD7mxZlKrPtLsQaHWvL9IO2VAa+lQ==}+ engines: {node: '>=18'}+ peerDependencies:+ '@langchain/core': '>=0.2.36 <0.3.0 || >=0.3.40 < 0.4.0'+ zod-to-json-schema: ^3.x+ peerDependenciesMeta:+ zod-to-json-schema:+ optional: true++ '@langchain/[email protected]':+ resolution: {integrity: sha512-hBQIWjcVxGS7tgVvgBBmrZ5jSaJ8nu9g6V64/Tx6KGjkW7VdGmUvqCO+koiQCOZVL7PBJkHWAvDsbghPYXiZEA==}+ engines: {node: '>=18'}+ peerDependencies:+ '@langchain/core': '>=0.3.48 <0.4.0'+'@lerna/[email protected]':resolution: {integrity: sha512-1yn1MvWn2Yz0SFgTTQnef2m1YedF7KwqLLVIOrGkgQrkVHzsveAIk1A1RcRa2yyUh+siKI1YcJ7lUZIEt+qQ3Q==}engines: {node: '>=18.0.0'}@@ -3569,6 +3608,10 @@ packages:resolution: {integrity: sha512-0/A9rDy9P7cJ+8w1c9WD9V//9Wj15Ce2MPz8Ri6032usz+NfePxx5AcN3bN+r6ZL6jEo066/yNYB3tn4pQEx+A==}hasBin: true+ resolution: {integrity: sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==}+ hasBin: true+resolution: {integrity: sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==}@@ -3750,25 +3793,6 @@ snapshots:'@composio/[email protected]': {}- '@composio/[email protected]([email protected])':- dependencies:- '@composio/client': 0.1.0-alpha.9- openai: 4.98.0([email protected])([email protected])- pusher-js: 8.4.0- zod: 3.24.4- transitivePeerDependencies:- - encoding- - ws-- '@composio/[email protected]([email protected])([email protected]([email protected])([email protected]))':- dependencies:- '@composio/core': 0.1.0-rc.5([email protected])- transitivePeerDependencies:- - encoding- - openai- - ws-'@emnapi/[email protected]':dependencies:'@emnapi/wasi-threads': 1.0.2@@ -3965,6 +3989,44 @@ snapshots:transitivePeerDependencies:- openai+ '@langchain/[email protected](@langchain/[email protected]([email protected]([email protected])([email protected])))':+ dependencies:+ uuid: 10.0.0++ '@langchain/[email protected](@langchain/[email protected]([email protected]([email protected])([email protected])))([email protected])':+ dependencies:+ '@types/json-schema': 7.0.15+ p-queue: 6.6.2+ p-retry: 4.6.2+ uuid: 9.0.1+ optionalDependencies:+ react: 19.1.0++ '@langchain/[email protected](@langchain/[email protected]([email protected]([email protected])([email protected])))([email protected])([email protected]([email protected]))':+ dependencies:+ '@langchain/langgraph-checkpoint': 0.0.17(@langchain/[email protected]([email protected]([email protected])([email protected])))+ '@langchain/langgraph-sdk': 0.0.74(@langchain/[email protected]([email protected]([email protected])([email protected])))([email protected])+ uuid: 10.0.0+ zod: 3.24.4+ optionalDependencies:+ zod-to-json-schema: 3.24.5([email protected])+ transitivePeerDependencies:+ - react++ '@langchain/[email protected](@langchain/[email protected]([email protected]([email protected])([email protected])))([email protected])':+ dependencies:+ js-tiktoken: 1.0.20+ openai: 4.98.0([email protected])([email protected])+ zod: 3.24.4+ zod-to-json-schema: 3.24.5([email protected])+ transitivePeerDependencies:+ - encoding+ - ws+dependencies:'@npmcli/arborist': 7.5.4@@ -7289,6 +7351,8 @@ snapshots:+ [email protected]: {}+dependencies:spdx-correct: 3.2.0