From e4b4d86ffdf69895fdfcd239bfb377df2c3e6d56 Mon Sep 17 00:00:00 2001 From: abhishekpatil4 Date: Mon, 18 Nov 2024 13:35:51 +0530 Subject: [PATCH 01/25] fix: actions docs --- docs/patterns/actions/action-guide-faqs.mdx | 83 ++++--------------- .../actions/action-guide-with-agents.mdx | 2 +- .../actions/action-guide-without-agents.mdx | 54 +++++++++++- docs/patterns/actions/custom_actions.mdx | 6 +- docs/patterns/actions/usecase.mdx | 6 +- 5 files changed, 76 insertions(+), 75 deletions(-) diff --git a/docs/patterns/actions/action-guide-faqs.mdx b/docs/patterns/actions/action-guide-faqs.mdx index ab1a56dba2..699fcd643b 100644 --- a/docs/patterns/actions/action-guide-faqs.mdx +++ b/docs/patterns/actions/action-guide-faqs.mdx @@ -8,14 +8,14 @@ description: "Understand more about Actions" -```python Python Selecting Actions via Name +```python Python tool_set = ComposioToolSet() tools = tool_set.get_tools(actions=[Action.GITHUB_CREATE_AN_ISSUE,Action.GITHUB_COMMIT_EVENT]) # can pass multiple actions ``` -```javascript Javascript Selecting Actions via Name +```javascript Javascript const toolset = new OpenAIToolSet(); const tools = await toolset.getTools({actions: ['github_issues_create','github_commit_event']}); @@ -25,47 +25,12 @@ const tools = await toolset.getTools({actions: ['github_issues_create','github_c - - - - -```Python Python Selecting Actions -use_case="Star a repo on github" - -action_enums=tool_set.find_actions_by_use_case(App.GITHUB,use_case=use_case) - -tools = tool_set.get_tools(actions=action_enums) - -# use tools as per your framework -``` - -```Javascript Javascript Selecting Actions -import { LangchainToolSet } from "composio-core"; - -const toolset = new LangchainToolSet({ - entityId: "default", -}); - -const actionsList = await toolset.client.actions.list({ - useCase: "create github issues", - apps: "github", -}); -``` - -```bash CLI Selecting Actions -composio actions --use-case 'get channel messages' --app 'slack' -``` - - - - - - - - +Yes, you can filter and get Actions in an App based on tags. -```python Selecting Actions via Apps & Tags +```python Python +from composio_langchain import ComposioToolSet, Action, App + tools = tool_set.get_tools(apps=[App.GITHUB]) # Filter by tags @@ -78,42 +43,26 @@ action_enums = toolset.find_actions_by_tags( tools = tool_set.get_tools(actions=action_enums) ``` - - - - -```javascript Selecting Actions via Apps -import { LangchainToolSet } from "composio-core"; +```javascript Javascript +import { OpenAIToolSet } from "composio-core"; -const toolset = new LangchainToolSet({ - apiKey: process.env.COMPOSIO_API_KEY, - entityId: "default" -}); +const composio_toolset = new OpenAIToolSet(); + +const tag = "meta"; -const actionsList = await toolset.client.actions.list({ - apps: "github" +const actions = await composio_toolset.getTools({ + apps: ["github"], + tags: [tag], }); -const actions = await toolset.getTools({ - actions: actionsList.items.map((action) => { - return action.name; - }) -}) +console.log(actions); ``` - - - - -```bash Selecting Actions via Apps +```bash CLI composio actions --app 'github' --tag 'code' -# Don't use tag if you want all actions ``` - - - diff --git a/docs/patterns/actions/action-guide-with-agents.mdx b/docs/patterns/actions/action-guide-with-agents.mdx index 8d1864f056..9b4f00465e 100644 --- a/docs/patterns/actions/action-guide-with-agents.mdx +++ b/docs/patterns/actions/action-guide-with-agents.mdx @@ -68,4 +68,4 @@ agent_executor.invoke({"input": task}) This code demonstrates how to use LLMs to execute an action. -Composio supports multiple frameworks for creating Agents including LlamaIndex, CrewAI, Letta, Langchain, you can see it in the **Supported Frameworks** section. +Composio supports multiple frameworks for creating Agents including LlamaIndex, CrewAI, Letta, LangChain, you can see it in the **Supported Frameworks** section. diff --git a/docs/patterns/actions/action-guide-without-agents.mdx b/docs/patterns/actions/action-guide-without-agents.mdx index 34e5601175..e97478a941 100644 --- a/docs/patterns/actions/action-guide-without-agents.mdx +++ b/docs/patterns/actions/action-guide-without-agents.mdx @@ -9,6 +9,58 @@ description: "Perform Actions with your account or on behalf of your users witho Composio lets you perform actions with your account or on behalf of your users. Feel free to check all the [tools](https://app.composio.dev/apps) we support. +### Get Parameters for an Action +Refer to the video below to learn how to get the parameters for an action via [API](/api-reference/actions/get-action) + + + +
+ +Get the parameters for executing an action programmatically + + + ```python Python +from composio import ComposioToolSet, Action +import json + +composio_toolset = ComposioToolSet() + +# Get the action schema +action_schema = composio_toolset.get_action_schemas(actions=[Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER]) + +# Print the parameters in a readable format +print(json.dumps(action_schema[0].parameters.properties, indent=2)) +``` + +```javascript Javascript +import { OpenAIToolSet } from "composio-core"; + +const composio_toolset = new OpenAIToolSet(); + +const schema = await composio_toolset.getActionsSchema({ + actions: ["github_star_a_repository_for_the_authenticated_user"], +}); + +console.log(JSON.stringify(schema[0].parameters.properties, null, 2)); + ``` + + +```bash Output +{ + "owner": { + "description": "The account owner of the repository. The name is not case sensitive. Please provide a value of type string. This parameter is required.", + "title": "Owner", + "type": "string" + }, + "repo": { + "description": "The name of the repository without the `.git` extension. The name is not case sensitive. . Please provide a value of type string. This parameter is required.", + "title": "Repo", + "type": "string" + } +} +``` + + ### Execute Actions without Agents To execute actions without using Agents, you can manually supply the parameters to execute the action or use natural language. @@ -53,7 +105,7 @@ console.log("Custom auth action response", customAuthAction) ``` -## Execute Actions with Natural Language +### Execute Actions with Natural Language You can also execute Actions by passing in natural language prompts without specific parameters ```python Python diff --git a/docs/patterns/actions/custom_actions.mdx b/docs/patterns/actions/custom_actions.mdx index c1705a2781..18a9a70fb1 100644 --- a/docs/patterns/actions/custom_actions.mdx +++ b/docs/patterns/actions/custom_actions.mdx @@ -7,12 +7,12 @@ description: "Guide to creating Custom Actions for existing tool or new tool" ## What are Custom Actions? -- Extend the functionality of existing tools by creating a custom action which utilises the existing authentication. (Fetch emails from Gmail) -- Write a custom action code snippet to execute the custom action (Check if number is even or odd) +- Extend the functionality of existing tools by creating a custom action which utilises the existing authentication. (e.g.,fetch emails from Gmail) +- Create standalone custom actions for any functionality you need (e.g., data processing, calculations, or integrations with other services) -Custom Actions can be created for any existing tool in Composio, allowing you to tailor the functionality to your specific needs while leveraging the existing authentication. +Custom Actions are flexible building blocks that let you create any functionality you need - from simple calculations to complex integrations. They work seamlessly with Composio's authentication system for existing tools, or can run independently for custom logic. ## Creating a Custom Action diff --git a/docs/patterns/actions/usecase.mdx b/docs/patterns/actions/usecase.mdx index 538d8b61d5..d5d8d4d515 100644 --- a/docs/patterns/actions/usecase.mdx +++ b/docs/patterns/actions/usecase.mdx @@ -11,14 +11,14 @@ Find relevant actions for your use case by describing what you want to accomplis -```Python Python Fetch Actions using use-case +```Python Python use_case="Star a repo on github" action_enums=toolset.find_actions_by_use_case(App.GITHUB, use_case=use_case) tools = toolset.get_tools(actions=action_enums) # use tools as per your framework ``` -```Javascript Javascript Fetch Actions using use-case +```Javascript Javascript import { LangchainToolSet } from "composio-core"; const toolset = new LangchainToolSet({ @@ -31,7 +31,7 @@ const actionsList = await toolset.client.actions.list({ }); ``` -```bash CLI Fetch Actions using use-case +```bash CLI composio actions --use-case 'get channel messages' --app 'slack' ``` \ No newline at end of file From 053e5bec38f7e07c98a577c8046ad7ddf4e5fdf3 Mon Sep 17 00:00:00 2001 From: abhishekpatil4 Date: Tue, 19 Nov 2024 12:51:01 +0530 Subject: [PATCH 02/25] feat: improve code description --- docs/patterns/actions/action-guide-faqs.mdx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/patterns/actions/action-guide-faqs.mdx b/docs/patterns/actions/action-guide-faqs.mdx index 699fcd643b..8a151625a3 100644 --- a/docs/patterns/actions/action-guide-faqs.mdx +++ b/docs/patterns/actions/action-guide-faqs.mdx @@ -19,7 +19,7 @@ tools = tool_set.get_tools(actions=[Action.GITHUB_CREATE_AN_ISSUE,Action.GITHUB_ const toolset = new OpenAIToolSet(); const tools = await toolset.getTools({actions: ['github_issues_create','github_commit_event']}); -// can pass multiple actions +# can pass multiple actions ``` @@ -27,6 +27,12 @@ const tools = await toolset.getTools({actions: ['github_issues_create','github_c Yes, you can filter and get Actions in an App based on tags. +For example, you can: +- Filter all user-related Actions using the "users" tag +- Retrieve metadata-related Actions using the "meta" tag + +Here's how you can implement tag-based filtering: + ```python Python from composio_langchain import ComposioToolSet, Action, App @@ -49,6 +55,7 @@ import { OpenAIToolSet } from "composio-core"; const composio_toolset = new OpenAIToolSet(); +// Filter by tags const tag = "meta"; const actions = await composio_toolset.getTools({ From fcd04fa9f85c6558953c1f6407f3da83739ac533 Mon Sep 17 00:00:00 2001 From: abhishekpatil4 Date: Tue, 19 Nov 2024 13:17:56 +0530 Subject: [PATCH 03/25] feat: enhance descritpion --- .../actions/action-guide-without-agents.mdx | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/patterns/actions/action-guide-without-agents.mdx b/docs/patterns/actions/action-guide-without-agents.mdx index e97478a941..490e35cb3c 100644 --- a/docs/patterns/actions/action-guide-without-agents.mdx +++ b/docs/patterns/actions/action-guide-without-agents.mdx @@ -7,17 +7,27 @@ description: "Perform Actions with your account or on behalf of your users witho ## Using Actions -Composio lets you perform actions with your account or on behalf of your users. Feel free to check all the [tools](https://app.composio.dev/apps) we support. +Composio lets you perform actions with your account or on behalf of your users. When executing actions without agents, you'll need to provide the required parameters. There are two ways to obtain these parameters: + +1. Through the [API Section](/api-reference/actions/get-action) of our documentation +2. Programmatically using our SDK + +Feel free to check all the [tools](https://app.composio.dev/apps) we support. ### Get Parameters for an Action -Refer to the video below to learn how to get the parameters for an action via [API](/api-reference/actions/get-action) +Below are demonstrations of both methods to get the parameters for an action: + +#### Using the [API Section](/api-reference/actions/get-action) from the Documentation -
+1. Navigate to the [API Section](/api-reference/actions/get-action) of our documentation +2. Click on **Get Action** under the **Actions** category +3. Enter your Composio API key and the Action ID +4. The **parameters** attribute in the response contains the required parameters for executing the action -Get the parameters for executing an action programmatically +#### Using the SDK ```python Python from composio import ComposioToolSet, Action From 165a3753ea8c7038f1c616a687c48fb554a822c5 Mon Sep 17 00:00:00 2001 From: abhishekpatil4 Date: Tue, 19 Nov 2024 16:13:15 +0530 Subject: [PATCH 04/25] feat: replace actions name with tools | add what-are-tools page --- docs/patterns/tools/action-guide-faqs.mdx | 86 ++++++ .../tools/action-guide-with-agents.mdx | 71 +++++ .../tools/action-guide-without-agents.mdx | 139 +++++++++ docs/patterns/tools/custom_actions.mdx | 269 ++++++++++++++++++ docs/patterns/tools/usecase.mdx | 37 +++ docs/patterns/tools/what-are-tools.mdx | 25 ++ 6 files changed, 627 insertions(+) create mode 100644 docs/patterns/tools/action-guide-faqs.mdx create mode 100644 docs/patterns/tools/action-guide-with-agents.mdx create mode 100644 docs/patterns/tools/action-guide-without-agents.mdx create mode 100644 docs/patterns/tools/custom_actions.mdx create mode 100644 docs/patterns/tools/usecase.mdx create mode 100644 docs/patterns/tools/what-are-tools.mdx diff --git a/docs/patterns/tools/action-guide-faqs.mdx b/docs/patterns/tools/action-guide-faqs.mdx new file mode 100644 index 0000000000..8a151625a3 --- /dev/null +++ b/docs/patterns/tools/action-guide-faqs.mdx @@ -0,0 +1,86 @@ +--- +title: "๐Ÿ› ๏ธ What else can I do with Actions?" +sidebarTitle: "Actions - FAQs" +icon: "wand-magic-sparkles" +description: "Understand more about Actions" +--- + + + + +```python Python +tool_set = ComposioToolSet() + +tools = tool_set.get_tools(actions=[Action.GITHUB_CREATE_AN_ISSUE,Action.GITHUB_COMMIT_EVENT]) +# can pass multiple actions +``` + +```javascript Javascript +const toolset = new OpenAIToolSet(); + +const tools = await toolset.getTools({actions: ['github_issues_create','github_commit_event']}); +# can pass multiple actions +``` + + + + + +Yes, you can filter and get Actions in an App based on tags. +For example, you can: +- Filter all user-related Actions using the "users" tag +- Retrieve metadata-related Actions using the "meta" tag + +Here's how you can implement tag-based filtering: + + +```python Python +from composio_langchain import ComposioToolSet, Action, App + +tools = tool_set.get_tools(apps=[App.GITHUB]) + +# Filter by tags +tag = "users" + +action_enums = toolset.find_actions_by_tags( + App.GITHUB, + tags=[tag], +) + +tools = tool_set.get_tools(actions=action_enums) +``` + +```javascript Javascript +import { OpenAIToolSet } from "composio-core"; + +const composio_toolset = new OpenAIToolSet(); + +// Filter by tags +const tag = "meta"; + +const actions = await composio_toolset.getTools({ + apps: ["github"], + tags: [tag], +}); + +console.log(actions); +``` + +```bash CLI +composio actions --app 'github' --tag 'code' +``` + + + + + + +```curl curl +curl --request GET \ + --url https://backend.composio.dev/api/v2/actions \ + --header 'X-API-Key: ' +``` + + + + diff --git a/docs/patterns/tools/action-guide-with-agents.mdx b/docs/patterns/tools/action-guide-with-agents.mdx new file mode 100644 index 0000000000..9b4f00465e --- /dev/null +++ b/docs/patterns/tools/action-guide-with-agents.mdx @@ -0,0 +1,71 @@ +--- +title: "๐Ÿ› ๏ธ How can I execute Actions with my AI Agent?" +sidebarTitle: "Execute Actions with Agents" +icon: "robot" +description: "Perform Actions with your account or on behalf of your users with Agents" +--- +## Using Actions + +Composio lets you perform actions with your account or on behalf of your users. Feel free to check all the [tools](https://app.composio.dev/apps) we support. + +### Execute Actions with Agents + +To execute actions with your account or on behalf of your users, you can use the following code. + + +```python Python +from langchain.agents import create_openai_functions_agent, AgentExecutor +from langchain import hub +from langchain_openai import ChatOpenAI +from composio_langchain import ComposioToolSet, Action, App +import os + + +llm = ChatOpenAI(model="gpt-4o") + +prompt = hub.pull("hwchase17/openai-functions-agent") + +# Get All the tools +tool_set = ComposioToolSet() +tools = tool_set.get_tools(actions=[Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER], tags=[]) + +# Define task +task = "Star a repo composiohq/composio on GitHub" + +agent = create_openai_functions_agent(llm, tools, prompt) +agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True) + +# Execute using agent_executor +agent_executor.invoke({"input": task}) +``` + +```javascript JavaScript + import { LangchainToolSet } from "composio-core"; + import { ChatOpenAI } from "@langchain/openai"; + import { AgentExecutor, createOpenAIFunctionsAgent } from "langchain/agents"; + import { pull } from "langchain/hub"; + + + (async () => { + const llm = new ChatOpenAI({ model: "gpt-4-turbo" }); + const composioToolset = new LangchainToolSet({ apiKey: process.env.COMPOSIO_API_KEY }); + const tools = await composioToolset.getTools({ actions: ["github_issues_create"] }); + const prompt = await pull("hwchase17/openai-functions-agent"); + + const agent = await createOpenAIFunctionsAgent({ llm, tools, prompt }); + const agentExecutor = new AgentExecutor({ agent, tools, verbose: true }); + const issueDetails = { + TITLE: "Sample issue", + DESCRIPTION: "Sample issue for the repo - himanshu-dixit/custom-repo-breaking" + }; + + const result = await agentExecutor.invoke({ + input: `Create a GitHub issue with the following details: ${JSON.stringify(issueDetails)}` + }); + return result.output; + })(); + ``` + + +This code demonstrates how to use LLMs to execute an action. +Composio supports multiple frameworks for creating Agents including LlamaIndex, CrewAI, Letta, LangChain, you can see it in the **Supported Frameworks** section. diff --git a/docs/patterns/tools/action-guide-without-agents.mdx b/docs/patterns/tools/action-guide-without-agents.mdx new file mode 100644 index 0000000000..490e35cb3c --- /dev/null +++ b/docs/patterns/tools/action-guide-without-agents.mdx @@ -0,0 +1,139 @@ +--- +title: "๐Ÿ› ๏ธ How can I execute Actions without my AI Agent?" +sidebarTitle: "Execute Actions without Agents" +icon: "fax" +description: "Perform Actions with your account or on behalf of your users without Agents" +--- + +## Using Actions + +Composio lets you perform actions with your account or on behalf of your users. When executing actions without agents, you'll need to provide the required parameters. There are two ways to obtain these parameters: + +1. Through the [API Section](/api-reference/actions/get-action) of our documentation +2. Programmatically using our SDK + +Feel free to check all the [tools](https://app.composio.dev/apps) we support. + +### Get Parameters for an Action + +Below are demonstrations of both methods to get the parameters for an action: + +#### Using the [API Section](/api-reference/actions/get-action) from the Documentation + + +1. Navigate to the [API Section](/api-reference/actions/get-action) of our documentation +2. Click on **Get Action** under the **Actions** category +3. Enter your Composio API key and the Action ID +4. The **parameters** attribute in the response contains the required parameters for executing the action + + +#### Using the SDK + + ```python Python +from composio import ComposioToolSet, Action +import json + +composio_toolset = ComposioToolSet() + +# Get the action schema +action_schema = composio_toolset.get_action_schemas(actions=[Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER]) + +# Print the parameters in a readable format +print(json.dumps(action_schema[0].parameters.properties, indent=2)) +``` + +```javascript Javascript +import { OpenAIToolSet } from "composio-core"; + +const composio_toolset = new OpenAIToolSet(); + +const schema = await composio_toolset.getActionsSchema({ + actions: ["github_star_a_repository_for_the_authenticated_user"], +}); + +console.log(JSON.stringify(schema[0].parameters.properties, null, 2)); + ``` + + +```bash Output +{ + "owner": { + "description": "The account owner of the repository. The name is not case sensitive. Please provide a value of type string. This parameter is required.", + "title": "Owner", + "type": "string" + }, + "repo": { + "description": "The name of the repository without the `.git` extension. The name is not case sensitive. . Please provide a value of type string. This parameter is required.", + "title": "Repo", + "type": "string" + } +} +``` + + +### Execute Actions without Agents + +To execute actions without using Agents, you can manually supply the parameters to execute the action or use natural language. + + + ```python Python Star a repo +from composio import ComposioToolSet, Action + +tool_set = ComposioToolSet(entity_id="Jessica") +#If you did not run 'composio login' in the CLI, you can use API Key like this: +#tool_set = ComposioToolSet(api_key, entity_id="Jessica") + +#You can change the repo you want to star by modifying the parameters +tool_set.execute_action( + action=Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER, + params={"owner": "composiohq", "repo": "composio"}, + entity_id="Jessica", +) +``` + +```javascript JavaScript Get Hypermedia links in GitHub +import { OpenAIToolSet } from "composio-core"; + +const toolset = new OpenAIToolSet(); + +const customAuthAction = await toolset.client.actions.execute({ + actionName: "GITHUB_GITHUB_API_ROOT", + requestBody: { + appName: "github", + authConfig: { + parameters: [{ + name: "Authorization", + in: "header", + value: `Bearer YOUR_API_KEY` + }] + }, + input: {} + } +}); + +console.log("Custom auth action response", customAuthAction) + ``` + + +### Execute Actions with Natural Language +You can also execute Actions by passing in natural language prompts without specific parameters + +```python Python + tool_set.execute_action( + action=Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER, + params={}, + text="Star the repo composiohq/composio", + entity_id="Jessica", + ) +``` + +```javascript JavaScript + await toolset.getEntity("Jessica").execute( + 'github_star_a_repository_for_the_authenticated_user', + {}, + "Star the repo composiohq/composio" + ); +``` + + +
\ No newline at end of file diff --git a/docs/patterns/tools/custom_actions.mdx b/docs/patterns/tools/custom_actions.mdx new file mode 100644 index 0000000000..18a9a70fb1 --- /dev/null +++ b/docs/patterns/tools/custom_actions.mdx @@ -0,0 +1,269 @@ +--- +title: "Custom Actions" +sidebarTitle: "Building Custom Actions" +icon: "hammer" +description: "Guide to creating Custom Actions for existing tool or new tool" +--- + +## What are Custom Actions? + +- Extend the functionality of existing tools by creating a custom action which utilises the existing authentication. (e.g.,fetch emails from Gmail) +- Create standalone custom actions for any functionality you need (e.g., data processing, calculations, or integrations with other services) + + + +Custom Actions are flexible building blocks that let you create any functionality you need - from simple calculations to complex integrations. They work seamlessly with Composio's authentication system for existing tools, or can run independently for custom logic. + + +## Creating a Custom Action + + + + + +```python Python +from composio import ComposioToolSet, App, action + +toolset = ComposioToolSet() +``` +```javascript Javascript +import { OpenAIToolSet } from "composio-core" +import { z } from "zod" + +const toolset = new OpenAIToolSet({}) +``` + + + + + + +As `gmail` toolname is already registered in Composio, `auth` dictionary will be automatically provided! + + +```python Custom Action - Gmail (python) +@action(toolname="gmail", requires=["example-pypi-package"]) # supports any package +def my_custom_action(auth: dict, account_id: str) -> str: # Uses existing gmail auth + """ + Fetch emails from Gmail account for last 24 hours + + :param account_id: Account ID, pass 'me' for default account + :param auth: Authentication dictionary provided by Composio for Gmail + :return info: Gmail emails information + """ + + # fetch authentication headers + headers = auth["headers"] + query_params = auth["query_params"] + base_url = auth["base_url"] + + yesterday_dateTime = int( + (datetime.datetime.now() + datetime.timedelta(days=-1)).timestamp() + ) + + if account_id and account_id != "": + custom_endpoint_url = f"/gmail/v1/users/{account_id}/messages?q=after:{yesterday_dateTime}" + else: + custom_endpoint_url = f"/gmail/v1/users/me/messages?q=after:{yesterday_dateTime}" + + # add query params to the url + for key, value in query_params.items(): + custom_endpoint_url += f"&{key}={value}" + + url = f"{base_url}{custom_endpoint_url}" + + response = requests.get(url, headers=headers) + + if response.status_code == 200: + print("Successfully fetched emails:", response.json()) + else: + print("Error fetching emails:", response.status_code, response.json()) + return str(response) +``` + +```javascript Custom Action - Gmail (javascript) +await toolset.createAction({ + actionName: "myCustomAction", + toolName: "gmail", + description: "Fetch emails from Gmail account for last 24 hours", + inputParams: z.object({ + accountId: z.string().describe("Gmail account ID. Defaults to the primary account, which is 'me'."), + }), + callback: async (inputParams, authCredentials) => { + const headers = authCredentials.headers; + const query_params = authCredentials.query_params; + const base_url = authCredentials.baseUrl; + + const oneDayAgo = Math.floor(Date.now() / 1000) - 86400; + const customEndpointUrl = `/gmail/v1/users/${inputParams.accountId}/messages?q=after:${oneDayAgo}`; + const url = `${base_url}${customEndpointUrl}`; + const response = await fetch(url, { headers }); + + if (response.ok) { + const data = await response.json(); + console.log("Successfully fetched emails:", data); + return data; + } else { + const errorData = await response.json(); + console.error("Error fetching emails:", response.status, errorData); + throw new Error(`Error fetching emails: ${response.status}`); + } + } +}); +``` + + + + + +```python Python +@action(toolname="cow", requires=["cowsay"]) +def my_custom_action(account_id: str) -> str: + """ + Cow will say whatever you want it to say. + + :param account_id: Account ID, pass 'me' for default account + :return greeting: Formatted message. + """ + import cowsay + + return cowsay.get_output_string("cow", account_id) +``` +```javascript JavaScript +await toolset.createAction({ + actionName: "myCustomAction", + description: "Cow will say whatever you want it to say. This can be used to print text in cow style", + inputParams: z.object({ + accountId: z.string() + }), + callback: async (inputParams) => { + const accountId = inputParams.accountId; + const cowMessage = `Cow says: ${accountId}`; + return cowMessage; + } +}); +``` + + + + + + +We can execute the custom action without Agents as well + + + +```python Python +from composio import ComposioToolSet + +toolset = ComposioToolSet() +toolset.execute_action( + action=my_custom_action, + params={ + 'account_id':'me' + }, +) +``` + +```javascript JavaScript +console.log( + await toolset.executeAction( + "myCustomAction", + { accountId: "me" } + ) +) +``` + + + + +```python Python Executing Custom Action with Agent +from openai import OpenAI +from composio_openai import ComposioToolSet + +openai_client = OpenAI() +# Initialise the Composio Tool Set +composio_toolset = ComposioToolSet() + +# Get GitHub tools that are pre-configured +# Retrieve actions +actions = composio_toolset.get_tools(actions=[my_custom_action]) + +my_task = "Fetch emails from Gmail account for last 24 hours" + +# Setup openai assistant +assistant_instruction = "You are a super intelligent personal assistant" + +# Prepare assistant +assistant = openai_client.beta.assistants.create( + name="Personal Assistant", + instructions=assistant_instruction, + model="gpt-4-turbo-preview", + tools=actions, # type: ignore +) + +# create a thread +thread = openai_client.beta.threads.create() +message = openai_client.beta.threads.messages.create( + thread_id=thread.id, role="user", content=my_task +) + +# Execute Agent with integrations + +run = openai_client.beta.threads.runs.create( + thread_id=thread.id, assistant_id=assistant.id +) + +# Execute function calls +response_after_tool_calls = composio_toolset.wait_and_handle_assistant_tool_calls( + client=openai_client, + run=run, + thread=thread, +) + +url = f"https://platform.openai.com/playground/assistants?assistant={assistant.id}&thread={thread.id}" + +print("Visit this URL to view the thread: ", url) +``` + +```javascript Javascript Custom Action with Agent +const tools = await toolset.getTools({ actions: ["myCustomAction"] }); +const instruction = "Fetch emails from Gmail account for last 24 hours" + +const client = new OpenAI({ apiKey: process.env.OPEN_AI_API_KEY }) +const response = await client.chat.completions.create({ + model: "gpt-4-turbo", + messages: [{ + role: "user", + content: instruction, + }], + tools: tools, + tool_choice: "auto", +}) + +console.log("Result", await toolset.handleToolCall(response)); +``` + + + + + +Output from executing Custom Action without Agents + +```shell Output from executing Custom Action without Agents +[INFO] Logging is set to INFO, use `logging_level` argument or `COMPOSIO_LOGGING_LEVEL` change this +[INFO] Executing `GMAIL_MY_CUSTOM_ACTION` with params={'query': 'test_query'} and metadata=None connected_account_id=None +[INFO] Got response={'data': {'info': {'headers': {'Authorization': 'Bearer KEY', 'x-request-id': '2c65e8b'}, 'base_url': 'https://api.github.com', 'query_params': {}}}, 'error': None, 'successful'... +{'data': {'info': {'headers': {'Authorization': 'Bearer KEY', 'x-request-id': '2c65e8b'}, 'base_url': 'https://api.github.com', 'query_params': {}}}, 'error': None, 'successful': True} +``` + + + + +### Why Use Custom Actions? + +Custom Actions provide several advantages: + +- **Data privacy:** Execution happens on the userโ€™s machine, ensuring sensitive data doesnโ€™t leave the local environment. +- **Flexibility:** Users can create and customize as many tools and actions as needed. +- **Compatibility:** Custom actions can be integrated seamlessly across various Composio-supported platforms. diff --git a/docs/patterns/tools/usecase.mdx b/docs/patterns/tools/usecase.mdx new file mode 100644 index 0000000000..d5d8d4d515 --- /dev/null +++ b/docs/patterns/tools/usecase.mdx @@ -0,0 +1,37 @@ +--- +title: "Finding Actions by Use Case" +sidebarTitle: "Actions by Use Case" +icon: "magnifying-glass" +description: "This documentation will guide you through the process of use case-based action finding in Composio." +--- + +Find relevant actions for your use case by describing what you want to accomplish in natural language. + +This approach is crucial because AI agents typically perform best with a limited set of actions. + + + +```Python Python +use_case="Star a repo on github" + +action_enums=toolset.find_actions_by_use_case(App.GITHUB, use_case=use_case) +tools = toolset.get_tools(actions=action_enums) # use tools as per your framework +``` + +```Javascript Javascript +import { LangchainToolSet } from "composio-core"; + +const toolset = new LangchainToolSet({ + entityId: "default", +}); + +const actionsList = await toolset.client.actions.list({ + useCase: "create github issues", + apps: "github", +}); +``` + +```bash CLI +composio actions --use-case 'get channel messages' --app 'slack' +``` + \ No newline at end of file diff --git a/docs/patterns/tools/what-are-tools.mdx b/docs/patterns/tools/what-are-tools.mdx new file mode 100644 index 0000000000..e1f410bab0 --- /dev/null +++ b/docs/patterns/tools/what-are-tools.mdx @@ -0,0 +1,25 @@ +--- +title: "๐Ÿ› ๏ธ What are tools?" +sidebarTitle: "What are tools?" +icon: "question" +description: "Learn about tools in Composio" +--- +### What are tools? + +Large Language Models (LLMs) are like a highly intelligent person who can understand and reason about almost anything but is sitting in an empty room with no ability to interact with the outside world. They can think and talk about sending emails, creating a ticket on Jira, or cloning a repository from github, but can't actually DO these things. + +This is where tools come in. Tools give this intelligent being specific abilities to interact with the real world. Many AI models support tool calling (also called function calling). + +### How tool calling works +AI models with tool calling capabilities decide when and how to use specific tools to meet user requests. Developers create and provide these tools, equipping the AI with a toolbox to select the best tool for each task + +For example, if a user asks an LLM to send an email to `john@example.com` with subject `Meeting Tomorrow`, the LLM can use the [Gmail](https://app.composio.dev/app/gmail) tool's `GMAIL_SEND_EMAIL` action to send the email. + +LLM's thinking process: +1. Recognizes this requires email sending capability +2. Identifies the appropriate tool ([Gmail](https://app.composio.dev/app/gmail)) & action (`GMAIL_SEND_EMAIL`) +3. Structures the necessary parameters: + - recipient: john@example.com + - subject: "Meeting Tomorrow" + - body: [drafts appropriate content] +4. Calls the action with these parameters From 7ea8356df26924724d2b766c3d62768d401681b1 Mon Sep 17 00:00:00 2001 From: abhishekpatil4 Date: Tue, 19 Nov 2024 16:28:26 +0530 Subject: [PATCH 05/25] feat: add note --- docs/patterns/tools/what-are-tools.mdx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/patterns/tools/what-are-tools.mdx b/docs/patterns/tools/what-are-tools.mdx index e1f410bab0..5bb114e756 100644 --- a/docs/patterns/tools/what-are-tools.mdx +++ b/docs/patterns/tools/what-are-tools.mdx @@ -10,6 +10,10 @@ Large Language Models (LLMs) are like a highly intelligent person who can unders This is where tools come in. Tools give this intelligent being specific abilities to interact with the real world. Many AI models support tool calling (also called function calling). + +The term **tools** and **actions** are used interchangeably in the further documentation + + ### How tool calling works AI models with tool calling capabilities decide when and how to use specific tools to meet user requests. Developers create and provide these tools, equipping the AI with a toolbox to select the best tool for each task From 33c5a2f995604237226fcba51f6b66ac99d5b4f6 Mon Sep 17 00:00:00 2001 From: abhishekpatil4 Date: Tue, 19 Nov 2024 17:38:51 +0530 Subject: [PATCH 06/25] feat: revamp Actions/Tools page --- docs/mint.json | 13 +- docs/patterns/actions/action-guide-faqs.mdx | 86 ------ .../actions/action-guide-with-agents.mdx | 71 ----- .../actions/action-guide-without-agents.mdx | 139 --------- docs/patterns/actions/custom_actions.mdx | 269 ------------------ docs/patterns/actions/usecase.mdx | 37 --- docs/patterns/tools/what-are-tools.mdx | 55 +++- 7 files changed, 59 insertions(+), 611 deletions(-) delete mode 100644 docs/patterns/actions/action-guide-faqs.mdx delete mode 100644 docs/patterns/actions/action-guide-with-agents.mdx delete mode 100644 docs/patterns/actions/action-guide-without-agents.mdx delete mode 100644 docs/patterns/actions/custom_actions.mdx delete mode 100644 docs/patterns/actions/usecase.mdx diff --git a/docs/mint.json b/docs/mint.json index 359e7a1aaa..81c57bcec1 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -113,14 +113,15 @@ ] }, { - "group":"Actions", + "group":"Tools", "icon":"shuttle-space" , "pages":[ - "patterns/actions/action-guide-with-agents", - "patterns/actions/action-guide-without-agents", - "patterns/actions/custom_actions", - "patterns/actions/usecase", - "patterns/actions/action-guide-faqs" + "patterns/tools/what-are-tools", + "patterns/tools/action-guide-with-agents", + "patterns/tools/action-guide-without-agents", + "patterns/tools/custom_actions", + "patterns/tools/usecase", + "patterns/tools/action-guide-faqs" ] }, { diff --git a/docs/patterns/actions/action-guide-faqs.mdx b/docs/patterns/actions/action-guide-faqs.mdx deleted file mode 100644 index 8a151625a3..0000000000 --- a/docs/patterns/actions/action-guide-faqs.mdx +++ /dev/null @@ -1,86 +0,0 @@ ---- -title: "๐Ÿ› ๏ธ What else can I do with Actions?" -sidebarTitle: "Actions - FAQs" -icon: "wand-magic-sparkles" -description: "Understand more about Actions" ---- - - - - -```python Python -tool_set = ComposioToolSet() - -tools = tool_set.get_tools(actions=[Action.GITHUB_CREATE_AN_ISSUE,Action.GITHUB_COMMIT_EVENT]) -# can pass multiple actions -``` - -```javascript Javascript -const toolset = new OpenAIToolSet(); - -const tools = await toolset.getTools({actions: ['github_issues_create','github_commit_event']}); -# can pass multiple actions -``` - - - - - -Yes, you can filter and get Actions in an App based on tags. -For example, you can: -- Filter all user-related Actions using the "users" tag -- Retrieve metadata-related Actions using the "meta" tag - -Here's how you can implement tag-based filtering: - - -```python Python -from composio_langchain import ComposioToolSet, Action, App - -tools = tool_set.get_tools(apps=[App.GITHUB]) - -# Filter by tags -tag = "users" - -action_enums = toolset.find_actions_by_tags( - App.GITHUB, - tags=[tag], -) - -tools = tool_set.get_tools(actions=action_enums) -``` - -```javascript Javascript -import { OpenAIToolSet } from "composio-core"; - -const composio_toolset = new OpenAIToolSet(); - -// Filter by tags -const tag = "meta"; - -const actions = await composio_toolset.getTools({ - apps: ["github"], - tags: [tag], -}); - -console.log(actions); -``` - -```bash CLI -composio actions --app 'github' --tag 'code' -``` - - - - - - -```curl curl -curl --request GET \ - --url https://backend.composio.dev/api/v2/actions \ - --header 'X-API-Key: ' -``` - - - - diff --git a/docs/patterns/actions/action-guide-with-agents.mdx b/docs/patterns/actions/action-guide-with-agents.mdx deleted file mode 100644 index 9b4f00465e..0000000000 --- a/docs/patterns/actions/action-guide-with-agents.mdx +++ /dev/null @@ -1,71 +0,0 @@ ---- -title: "๐Ÿ› ๏ธ How can I execute Actions with my AI Agent?" -sidebarTitle: "Execute Actions with Agents" -icon: "robot" -description: "Perform Actions with your account or on behalf of your users with Agents" ---- -## Using Actions - -Composio lets you perform actions with your account or on behalf of your users. Feel free to check all the [tools](https://app.composio.dev/apps) we support. - -### Execute Actions with Agents - -To execute actions with your account or on behalf of your users, you can use the following code. - - -```python Python -from langchain.agents import create_openai_functions_agent, AgentExecutor -from langchain import hub -from langchain_openai import ChatOpenAI -from composio_langchain import ComposioToolSet, Action, App -import os - - -llm = ChatOpenAI(model="gpt-4o") - -prompt = hub.pull("hwchase17/openai-functions-agent") - -# Get All the tools -tool_set = ComposioToolSet() -tools = tool_set.get_tools(actions=[Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER], tags=[]) - -# Define task -task = "Star a repo composiohq/composio on GitHub" - -agent = create_openai_functions_agent(llm, tools, prompt) -agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True) - -# Execute using agent_executor -agent_executor.invoke({"input": task}) -``` - -```javascript JavaScript - import { LangchainToolSet } from "composio-core"; - import { ChatOpenAI } from "@langchain/openai"; - import { AgentExecutor, createOpenAIFunctionsAgent } from "langchain/agents"; - import { pull } from "langchain/hub"; - - - (async () => { - const llm = new ChatOpenAI({ model: "gpt-4-turbo" }); - const composioToolset = new LangchainToolSet({ apiKey: process.env.COMPOSIO_API_KEY }); - const tools = await composioToolset.getTools({ actions: ["github_issues_create"] }); - const prompt = await pull("hwchase17/openai-functions-agent"); - - const agent = await createOpenAIFunctionsAgent({ llm, tools, prompt }); - const agentExecutor = new AgentExecutor({ agent, tools, verbose: true }); - const issueDetails = { - TITLE: "Sample issue", - DESCRIPTION: "Sample issue for the repo - himanshu-dixit/custom-repo-breaking" - }; - - const result = await agentExecutor.invoke({ - input: `Create a GitHub issue with the following details: ${JSON.stringify(issueDetails)}` - }); - return result.output; - })(); - ``` - - -This code demonstrates how to use LLMs to execute an action. -Composio supports multiple frameworks for creating Agents including LlamaIndex, CrewAI, Letta, LangChain, you can see it in the **Supported Frameworks** section. diff --git a/docs/patterns/actions/action-guide-without-agents.mdx b/docs/patterns/actions/action-guide-without-agents.mdx deleted file mode 100644 index 490e35cb3c..0000000000 --- a/docs/patterns/actions/action-guide-without-agents.mdx +++ /dev/null @@ -1,139 +0,0 @@ ---- -title: "๐Ÿ› ๏ธ How can I execute Actions without my AI Agent?" -sidebarTitle: "Execute Actions without Agents" -icon: "fax" -description: "Perform Actions with your account or on behalf of your users without Agents" ---- - -## Using Actions - -Composio lets you perform actions with your account or on behalf of your users. When executing actions without agents, you'll need to provide the required parameters. There are two ways to obtain these parameters: - -1. Through the [API Section](/api-reference/actions/get-action) of our documentation -2. Programmatically using our SDK - -Feel free to check all the [tools](https://app.composio.dev/apps) we support. - -### Get Parameters for an Action - -Below are demonstrations of both methods to get the parameters for an action: - -#### Using the [API Section](/api-reference/actions/get-action) from the Documentation - - -1. Navigate to the [API Section](/api-reference/actions/get-action) of our documentation -2. Click on **Get Action** under the **Actions** category -3. Enter your Composio API key and the Action ID -4. The **parameters** attribute in the response contains the required parameters for executing the action - - -#### Using the SDK - - ```python Python -from composio import ComposioToolSet, Action -import json - -composio_toolset = ComposioToolSet() - -# Get the action schema -action_schema = composio_toolset.get_action_schemas(actions=[Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER]) - -# Print the parameters in a readable format -print(json.dumps(action_schema[0].parameters.properties, indent=2)) -``` - -```javascript Javascript -import { OpenAIToolSet } from "composio-core"; - -const composio_toolset = new OpenAIToolSet(); - -const schema = await composio_toolset.getActionsSchema({ - actions: ["github_star_a_repository_for_the_authenticated_user"], -}); - -console.log(JSON.stringify(schema[0].parameters.properties, null, 2)); - ``` - - -```bash Output -{ - "owner": { - "description": "The account owner of the repository. The name is not case sensitive. Please provide a value of type string. This parameter is required.", - "title": "Owner", - "type": "string" - }, - "repo": { - "description": "The name of the repository without the `.git` extension. The name is not case sensitive. . Please provide a value of type string. This parameter is required.", - "title": "Repo", - "type": "string" - } -} -``` - - -### Execute Actions without Agents - -To execute actions without using Agents, you can manually supply the parameters to execute the action or use natural language. - - - ```python Python Star a repo -from composio import ComposioToolSet, Action - -tool_set = ComposioToolSet(entity_id="Jessica") -#If you did not run 'composio login' in the CLI, you can use API Key like this: -#tool_set = ComposioToolSet(api_key, entity_id="Jessica") - -#You can change the repo you want to star by modifying the parameters -tool_set.execute_action( - action=Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER, - params={"owner": "composiohq", "repo": "composio"}, - entity_id="Jessica", -) -``` - -```javascript JavaScript Get Hypermedia links in GitHub -import { OpenAIToolSet } from "composio-core"; - -const toolset = new OpenAIToolSet(); - -const customAuthAction = await toolset.client.actions.execute({ - actionName: "GITHUB_GITHUB_API_ROOT", - requestBody: { - appName: "github", - authConfig: { - parameters: [{ - name: "Authorization", - in: "header", - value: `Bearer YOUR_API_KEY` - }] - }, - input: {} - } -}); - -console.log("Custom auth action response", customAuthAction) - ``` - - -### Execute Actions with Natural Language -You can also execute Actions by passing in natural language prompts without specific parameters - -```python Python - tool_set.execute_action( - action=Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER, - params={}, - text="Star the repo composiohq/composio", - entity_id="Jessica", - ) -``` - -```javascript JavaScript - await toolset.getEntity("Jessica").execute( - 'github_star_a_repository_for_the_authenticated_user', - {}, - "Star the repo composiohq/composio" - ); -``` - - -
\ No newline at end of file diff --git a/docs/patterns/actions/custom_actions.mdx b/docs/patterns/actions/custom_actions.mdx deleted file mode 100644 index 18a9a70fb1..0000000000 --- a/docs/patterns/actions/custom_actions.mdx +++ /dev/null @@ -1,269 +0,0 @@ ---- -title: "Custom Actions" -sidebarTitle: "Building Custom Actions" -icon: "hammer" -description: "Guide to creating Custom Actions for existing tool or new tool" ---- - -## What are Custom Actions? - -- Extend the functionality of existing tools by creating a custom action which utilises the existing authentication. (e.g.,fetch emails from Gmail) -- Create standalone custom actions for any functionality you need (e.g., data processing, calculations, or integrations with other services) - - - -Custom Actions are flexible building blocks that let you create any functionality you need - from simple calculations to complex integrations. They work seamlessly with Composio's authentication system for existing tools, or can run independently for custom logic. - - -## Creating a Custom Action - - - - - -```python Python -from composio import ComposioToolSet, App, action - -toolset = ComposioToolSet() -``` -```javascript Javascript -import { OpenAIToolSet } from "composio-core" -import { z } from "zod" - -const toolset = new OpenAIToolSet({}) -``` - - - - - - -As `gmail` toolname is already registered in Composio, `auth` dictionary will be automatically provided! - - -```python Custom Action - Gmail (python) -@action(toolname="gmail", requires=["example-pypi-package"]) # supports any package -def my_custom_action(auth: dict, account_id: str) -> str: # Uses existing gmail auth - """ - Fetch emails from Gmail account for last 24 hours - - :param account_id: Account ID, pass 'me' for default account - :param auth: Authentication dictionary provided by Composio for Gmail - :return info: Gmail emails information - """ - - # fetch authentication headers - headers = auth["headers"] - query_params = auth["query_params"] - base_url = auth["base_url"] - - yesterday_dateTime = int( - (datetime.datetime.now() + datetime.timedelta(days=-1)).timestamp() - ) - - if account_id and account_id != "": - custom_endpoint_url = f"/gmail/v1/users/{account_id}/messages?q=after:{yesterday_dateTime}" - else: - custom_endpoint_url = f"/gmail/v1/users/me/messages?q=after:{yesterday_dateTime}" - - # add query params to the url - for key, value in query_params.items(): - custom_endpoint_url += f"&{key}={value}" - - url = f"{base_url}{custom_endpoint_url}" - - response = requests.get(url, headers=headers) - - if response.status_code == 200: - print("Successfully fetched emails:", response.json()) - else: - print("Error fetching emails:", response.status_code, response.json()) - return str(response) -``` - -```javascript Custom Action - Gmail (javascript) -await toolset.createAction({ - actionName: "myCustomAction", - toolName: "gmail", - description: "Fetch emails from Gmail account for last 24 hours", - inputParams: z.object({ - accountId: z.string().describe("Gmail account ID. Defaults to the primary account, which is 'me'."), - }), - callback: async (inputParams, authCredentials) => { - const headers = authCredentials.headers; - const query_params = authCredentials.query_params; - const base_url = authCredentials.baseUrl; - - const oneDayAgo = Math.floor(Date.now() / 1000) - 86400; - const customEndpointUrl = `/gmail/v1/users/${inputParams.accountId}/messages?q=after:${oneDayAgo}`; - const url = `${base_url}${customEndpointUrl}`; - const response = await fetch(url, { headers }); - - if (response.ok) { - const data = await response.json(); - console.log("Successfully fetched emails:", data); - return data; - } else { - const errorData = await response.json(); - console.error("Error fetching emails:", response.status, errorData); - throw new Error(`Error fetching emails: ${response.status}`); - } - } -}); -``` - - - - - -```python Python -@action(toolname="cow", requires=["cowsay"]) -def my_custom_action(account_id: str) -> str: - """ - Cow will say whatever you want it to say. - - :param account_id: Account ID, pass 'me' for default account - :return greeting: Formatted message. - """ - import cowsay - - return cowsay.get_output_string("cow", account_id) -``` -```javascript JavaScript -await toolset.createAction({ - actionName: "myCustomAction", - description: "Cow will say whatever you want it to say. This can be used to print text in cow style", - inputParams: z.object({ - accountId: z.string() - }), - callback: async (inputParams) => { - const accountId = inputParams.accountId; - const cowMessage = `Cow says: ${accountId}`; - return cowMessage; - } -}); -``` - - - - - - -We can execute the custom action without Agents as well - - - -```python Python -from composio import ComposioToolSet - -toolset = ComposioToolSet() -toolset.execute_action( - action=my_custom_action, - params={ - 'account_id':'me' - }, -) -``` - -```javascript JavaScript -console.log( - await toolset.executeAction( - "myCustomAction", - { accountId: "me" } - ) -) -``` - - - - -```python Python Executing Custom Action with Agent -from openai import OpenAI -from composio_openai import ComposioToolSet - -openai_client = OpenAI() -# Initialise the Composio Tool Set -composio_toolset = ComposioToolSet() - -# Get GitHub tools that are pre-configured -# Retrieve actions -actions = composio_toolset.get_tools(actions=[my_custom_action]) - -my_task = "Fetch emails from Gmail account for last 24 hours" - -# Setup openai assistant -assistant_instruction = "You are a super intelligent personal assistant" - -# Prepare assistant -assistant = openai_client.beta.assistants.create( - name="Personal Assistant", - instructions=assistant_instruction, - model="gpt-4-turbo-preview", - tools=actions, # type: ignore -) - -# create a thread -thread = openai_client.beta.threads.create() -message = openai_client.beta.threads.messages.create( - thread_id=thread.id, role="user", content=my_task -) - -# Execute Agent with integrations - -run = openai_client.beta.threads.runs.create( - thread_id=thread.id, assistant_id=assistant.id -) - -# Execute function calls -response_after_tool_calls = composio_toolset.wait_and_handle_assistant_tool_calls( - client=openai_client, - run=run, - thread=thread, -) - -url = f"https://platform.openai.com/playground/assistants?assistant={assistant.id}&thread={thread.id}" - -print("Visit this URL to view the thread: ", url) -``` - -```javascript Javascript Custom Action with Agent -const tools = await toolset.getTools({ actions: ["myCustomAction"] }); -const instruction = "Fetch emails from Gmail account for last 24 hours" - -const client = new OpenAI({ apiKey: process.env.OPEN_AI_API_KEY }) -const response = await client.chat.completions.create({ - model: "gpt-4-turbo", - messages: [{ - role: "user", - content: instruction, - }], - tools: tools, - tool_choice: "auto", -}) - -console.log("Result", await toolset.handleToolCall(response)); -``` - - - - - -Output from executing Custom Action without Agents - -```shell Output from executing Custom Action without Agents -[INFO] Logging is set to INFO, use `logging_level` argument or `COMPOSIO_LOGGING_LEVEL` change this -[INFO] Executing `GMAIL_MY_CUSTOM_ACTION` with params={'query': 'test_query'} and metadata=None connected_account_id=None -[INFO] Got response={'data': {'info': {'headers': {'Authorization': 'Bearer KEY', 'x-request-id': '2c65e8b'}, 'base_url': 'https://api.github.com', 'query_params': {}}}, 'error': None, 'successful'... -{'data': {'info': {'headers': {'Authorization': 'Bearer KEY', 'x-request-id': '2c65e8b'}, 'base_url': 'https://api.github.com', 'query_params': {}}}, 'error': None, 'successful': True} -``` - - - - -### Why Use Custom Actions? - -Custom Actions provide several advantages: - -- **Data privacy:** Execution happens on the userโ€™s machine, ensuring sensitive data doesnโ€™t leave the local environment. -- **Flexibility:** Users can create and customize as many tools and actions as needed. -- **Compatibility:** Custom actions can be integrated seamlessly across various Composio-supported platforms. diff --git a/docs/patterns/actions/usecase.mdx b/docs/patterns/actions/usecase.mdx deleted file mode 100644 index d5d8d4d515..0000000000 --- a/docs/patterns/actions/usecase.mdx +++ /dev/null @@ -1,37 +0,0 @@ ---- -title: "Finding Actions by Use Case" -sidebarTitle: "Actions by Use Case" -icon: "magnifying-glass" -description: "This documentation will guide you through the process of use case-based action finding in Composio." ---- - -Find relevant actions for your use case by describing what you want to accomplish in natural language. - -This approach is crucial because AI agents typically perform best with a limited set of actions. - - - -```Python Python -use_case="Star a repo on github" - -action_enums=toolset.find_actions_by_use_case(App.GITHUB, use_case=use_case) -tools = toolset.get_tools(actions=action_enums) # use tools as per your framework -``` - -```Javascript Javascript -import { LangchainToolSet } from "composio-core"; - -const toolset = new LangchainToolSet({ - entityId: "default", -}); - -const actionsList = await toolset.client.actions.list({ - useCase: "create github issues", - apps: "github", -}); -``` - -```bash CLI -composio actions --use-case 'get channel messages' --app 'slack' -``` - \ No newline at end of file diff --git a/docs/patterns/tools/what-are-tools.mdx b/docs/patterns/tools/what-are-tools.mdx index 5bb114e756..00a51c46cd 100644 --- a/docs/patterns/tools/what-are-tools.mdx +++ b/docs/patterns/tools/what-are-tools.mdx @@ -1,6 +1,6 @@ --- -title: "๐Ÿ› ๏ธ What are tools?" -sidebarTitle: "What are tools?" +title: "๐Ÿ› ๏ธ What are Tools/Actions?" +sidebarTitle: "What are Tools/Actions?" icon: "question" description: "Learn about tools in Composio" --- @@ -11,7 +11,7 @@ Large Language Models (LLMs) are like a highly intelligent person who can unders This is where tools come in. Tools give this intelligent being specific abilities to interact with the real world. Many AI models support tool calling (also called function calling). -The term **tools** and **actions** are used interchangeably in the further documentation +The term **tools** and **actions** are used interchangeably in the documentation ### How tool calling works @@ -27,3 +27,52 @@ LLM's thinking process: - subject: "Meeting Tomorrow" - body: [drafts appropriate content] 4. Calls the action with these parameters + + +### Tool calling with Composio + +At Composio, we offer tools for multiple platforms, accessible via Python and JavaScript SDKs. These platforms, referred to as **Apps** or **Tools**, include popular services like GitHub, Twitter, Salesforce, Jira, and Notion. Within each of these Apps, we provide **Actions**, which are essentially functions that can be executed. For example, you can send an email on Gmail, star a repository on GitHub, or create an issue on Jira. These tools can also be used directly, similar to function calls, without needing agents. + + +```python Python +from composio_langchain import ComposioToolSet, Action, App + +tool_set = ComposioToolSet() + +# Get all actions from a tool +tools = tool_set.get_tools(apps=[App.GITHUB]) + +# Get specific actions +tools = tool_set.get_tools(actions=[Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER]) +``` + +```javascript JavaScript +import { LangchainToolSet } from "composio-core"; + +const composioToolset = new LangchainToolSet(); + +// Get all actions from a tool +const tools = await composioToolset.getTools({ apps: ["github"] }); + +// Get specific actions +const tools = await composioToolset.getTools({ actions: ["github_star_a_repository_for_the_authenticated_user"] }); +``` + + +### Action Types + +1. **External Tool Actions**: Pre-configured actions for specific tools, such as creating issues or changing issue status in Jira. +2. **System Management Actions**: Actions that interact with the execution environment, like file system operations, shell commands, and browser automation. +3. **Custom Actions**: User-defined actions in Python or JavaScript that extend Composio's capabilities to interact with new or existing tools. + +### Action Limits + +Empirical evidence indicates that agents perform optimally when limited to **fewer than 20 actions**. Providing LLMs with too many actions can lead to significant performance issues, such as **increased response time** and **decreased accuracy**. + +To optimize agent performance, it's essential to limit the number of actions available. This can be achieved through effective action filtering strategies. Here are some recommended approaches: + +1. Use specific actions from a tool +2. Use tags to filter actions +3. Implement custom filtering logic + +By carefully curating the action set, you can significantly improve agent efficiency and response quality. From 1367e671b2739b67f6dc2a66506b881b41d22631 Mon Sep 17 00:00:00 2001 From: abhishekpatil4 Date: Tue, 19 Nov 2024 18:22:45 +0530 Subject: [PATCH 07/25] feat: renaming sidebar --- docs/patterns/tools/action-guide-with-agents.mdx | 2 +- docs/patterns/tools/action-guide-without-agents.mdx | 2 +- docs/patterns/tools/custom_actions.mdx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/patterns/tools/action-guide-with-agents.mdx b/docs/patterns/tools/action-guide-with-agents.mdx index 9b4f00465e..efb286027a 100644 --- a/docs/patterns/tools/action-guide-with-agents.mdx +++ b/docs/patterns/tools/action-guide-with-agents.mdx @@ -1,6 +1,6 @@ --- title: "๐Ÿ› ๏ธ How can I execute Actions with my AI Agent?" -sidebarTitle: "Execute Actions with Agents" +sidebarTitle: "Use Tools with Agents" icon: "robot" description: "Perform Actions with your account or on behalf of your users with Agents" --- diff --git a/docs/patterns/tools/action-guide-without-agents.mdx b/docs/patterns/tools/action-guide-without-agents.mdx index 490e35cb3c..966ca15318 100644 --- a/docs/patterns/tools/action-guide-without-agents.mdx +++ b/docs/patterns/tools/action-guide-without-agents.mdx @@ -1,6 +1,6 @@ --- title: "๐Ÿ› ๏ธ How can I execute Actions without my AI Agent?" -sidebarTitle: "Execute Actions without Agents" +sidebarTitle: "Use Tools without Agents" icon: "fax" description: "Perform Actions with your account or on behalf of your users without Agents" --- diff --git a/docs/patterns/tools/custom_actions.mdx b/docs/patterns/tools/custom_actions.mdx index 18a9a70fb1..a48a596017 100644 --- a/docs/patterns/tools/custom_actions.mdx +++ b/docs/patterns/tools/custom_actions.mdx @@ -1,6 +1,6 @@ --- title: "Custom Actions" -sidebarTitle: "Building Custom Actions" +sidebarTitle: "Build Tools" icon: "hammer" description: "Guide to creating Custom Actions for existing tool or new tool" --- From 7f33b52d1d8b20a00d776c5ebf30641e9901ff3c Mon Sep 17 00:00:00 2001 From: abhishekpatil4 Date: Tue, 19 Nov 2024 18:34:51 +0530 Subject: [PATCH 08/25] minor changes --- docs/patterns/tools/what-are-tools.mdx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/patterns/tools/what-are-tools.mdx b/docs/patterns/tools/what-are-tools.mdx index 00a51c46cd..6a13bbd720 100644 --- a/docs/patterns/tools/what-are-tools.mdx +++ b/docs/patterns/tools/what-are-tools.mdx @@ -73,6 +73,7 @@ To optimize agent performance, it's essential to limit the number of actions ava 1. Use specific actions from a tool 2. Use tags to filter actions -3. Implement custom filtering logic +3. Use use cases to filter actions +4. Implement custom filtering logic By carefully curating the action set, you can significantly improve agent efficiency and response quality. From 1612ab30c466e4ea26e7730fcba2e2c9aae3d1ab Mon Sep 17 00:00:00 2001 From: abhishekpatil4 Date: Tue, 19 Nov 2024 18:53:46 +0530 Subject: [PATCH 09/25] feat: add filter-actions page (select action by id, filter by tag, filter by usecase) | remove faqs page --- docs/mint.json | 3 +- docs/patterns/tools/action-guide-faqs.mdx | 86 ----------------- docs/patterns/tools/filter-actions.mdx | 108 ++++++++++++++++++++++ docs/patterns/tools/usecase.mdx | 37 -------- 4 files changed, 109 insertions(+), 125 deletions(-) delete mode 100644 docs/patterns/tools/action-guide-faqs.mdx create mode 100644 docs/patterns/tools/filter-actions.mdx delete mode 100644 docs/patterns/tools/usecase.mdx diff --git a/docs/mint.json b/docs/mint.json index 81c57bcec1..0582b9efc3 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -120,8 +120,7 @@ "patterns/tools/action-guide-with-agents", "patterns/tools/action-guide-without-agents", "patterns/tools/custom_actions", - "patterns/tools/usecase", - "patterns/tools/action-guide-faqs" + "patterns/tools/filter-actions" ] }, { diff --git a/docs/patterns/tools/action-guide-faqs.mdx b/docs/patterns/tools/action-guide-faqs.mdx deleted file mode 100644 index 8a151625a3..0000000000 --- a/docs/patterns/tools/action-guide-faqs.mdx +++ /dev/null @@ -1,86 +0,0 @@ ---- -title: "๐Ÿ› ๏ธ What else can I do with Actions?" -sidebarTitle: "Actions - FAQs" -icon: "wand-magic-sparkles" -description: "Understand more about Actions" ---- - - - - -```python Python -tool_set = ComposioToolSet() - -tools = tool_set.get_tools(actions=[Action.GITHUB_CREATE_AN_ISSUE,Action.GITHUB_COMMIT_EVENT]) -# can pass multiple actions -``` - -```javascript Javascript -const toolset = new OpenAIToolSet(); - -const tools = await toolset.getTools({actions: ['github_issues_create','github_commit_event']}); -# can pass multiple actions -``` - - - - - -Yes, you can filter and get Actions in an App based on tags. -For example, you can: -- Filter all user-related Actions using the "users" tag -- Retrieve metadata-related Actions using the "meta" tag - -Here's how you can implement tag-based filtering: - - -```python Python -from composio_langchain import ComposioToolSet, Action, App - -tools = tool_set.get_tools(apps=[App.GITHUB]) - -# Filter by tags -tag = "users" - -action_enums = toolset.find_actions_by_tags( - App.GITHUB, - tags=[tag], -) - -tools = tool_set.get_tools(actions=action_enums) -``` - -```javascript Javascript -import { OpenAIToolSet } from "composio-core"; - -const composio_toolset = new OpenAIToolSet(); - -// Filter by tags -const tag = "meta"; - -const actions = await composio_toolset.getTools({ - apps: ["github"], - tags: [tag], -}); - -console.log(actions); -``` - -```bash CLI -composio actions --app 'github' --tag 'code' -``` - - - - - - -```curl curl -curl --request GET \ - --url https://backend.composio.dev/api/v2/actions \ - --header 'X-API-Key: ' -``` - - - - diff --git a/docs/patterns/tools/filter-actions.mdx b/docs/patterns/tools/filter-actions.mdx new file mode 100644 index 0000000000..01abfb6db9 --- /dev/null +++ b/docs/patterns/tools/filter-actions.mdx @@ -0,0 +1,108 @@ +--- +title: "Filtering Actions" +sidebarTitle: "Filter Actions" +icon: "filter" +description: "This documentation will guide you through the process of filtering actions based on different criteria." +--- + +Filtering actions is crucial for optimizing AI agent performance by narrowing down the action set to the most relevant ones. + +### Selecting Actions by ID +You can select specific Actions from a given App by specifying action IDs. + +```python Python +from composio import ComposioToolSet, App, action + +toolset = ComposioToolSet() + +# can pass multiple actions +tools = toolset.get_tools(actions=[Action.GITHUB_CREATE_AN_ISSUE,Action.GITHUB_COMMIT_EVENT]) +``` + +```javascript Javascript +import { LangchainToolSet } from "composio-core"; + +const toolset = new LangchainToolSet(); + +// can pass multiple actions +const tools = await toolset.getTools({actions: ['github_issues_create','github_commit_event']}); +``` + + +### Filtering Actions by Tags +Filter the Actions in an App based on tags. +For example, you can: +- Filter all user-related Actions using the "users" tag +- Retrieve metadata-related Actions using the "meta" tag + + +```python Python +from composio_langchain import ComposioToolSet, Action, App + +tools = tool_set.get_tools(apps=[App.GITHUB]) + +# Filter by tags +tag = "users" + +action_enums = toolset.find_actions_by_tags( + App.GITHUB, + tags=[tag], +) + +tools = tool_set.get_tools(actions=action_enums) +``` + +```javascript Javascript +import { OpenAIToolSet } from "composio-core"; + +const composio_toolset = new OpenAIToolSet(); + +// Filter by tags +const tag = "meta"; + +const actions = await composio_toolset.getTools({ + apps: ["github"], + tags: [tag], +}); + +console.log(actions); +``` + +```bash CLI +composio actions --app 'github' --tag 'code' +``` + + +### Filtering Actions by Use Case +Find relevant actions for your use case by describing your use case in natural language. + +```Python Python +from composio import ComposioToolSet, App, action + +toolset = ComposioToolSet() + +# Specify the use case +use_case="Star a repo on github" + +action_enums=toolset.find_actions_by_use_case(App.GITHUB, use_case=use_case) +tools = toolset.get_tools(actions=action_enums) +``` + +```Javascript Javascript +import { LangchainToolSet } from "composio-core"; + +const toolset = new LangchainToolSet(); + +// Specify the use case +const useCase = "Star a repo on github"; + +const actionsList = await toolset.client.actions.list({ + useCase: useCase, + apps: "github", +}); +``` + +```bash CLI +composio actions --use-case 'star a repo on github' --app 'github' +``` + diff --git a/docs/patterns/tools/usecase.mdx b/docs/patterns/tools/usecase.mdx deleted file mode 100644 index d5d8d4d515..0000000000 --- a/docs/patterns/tools/usecase.mdx +++ /dev/null @@ -1,37 +0,0 @@ ---- -title: "Finding Actions by Use Case" -sidebarTitle: "Actions by Use Case" -icon: "magnifying-glass" -description: "This documentation will guide you through the process of use case-based action finding in Composio." ---- - -Find relevant actions for your use case by describing what you want to accomplish in natural language. - -This approach is crucial because AI agents typically perform best with a limited set of actions. - - - -```Python Python -use_case="Star a repo on github" - -action_enums=toolset.find_actions_by_use_case(App.GITHUB, use_case=use_case) -tools = toolset.get_tools(actions=action_enums) # use tools as per your framework -``` - -```Javascript Javascript -import { LangchainToolSet } from "composio-core"; - -const toolset = new LangchainToolSet({ - entityId: "default", -}); - -const actionsList = await toolset.client.actions.list({ - useCase: "create github issues", - apps: "github", -}); -``` - -```bash CLI -composio actions --use-case 'get channel messages' --app 'slack' -``` - \ No newline at end of file From 2aa60256fda2e97eb2a654dc2b872152e390185d Mon Sep 17 00:00:00 2001 From: abhishekpatil4 Date: Tue, 19 Nov 2024 21:58:20 +0530 Subject: [PATCH 10/25] feat: restructure docs --- docs/patterns/tools/custom_actions.mdx | 198 ++++++++++++------------- 1 file changed, 91 insertions(+), 107 deletions(-) diff --git a/docs/patterns/tools/custom_actions.mdx b/docs/patterns/tools/custom_actions.mdx index a48a596017..7db0ef79a0 100644 --- a/docs/patterns/tools/custom_actions.mdx +++ b/docs/patterns/tools/custom_actions.mdx @@ -7,7 +7,7 @@ description: "Guide to creating Custom Actions for existing tool or new tool" ## What are Custom Actions? -- Extend the functionality of existing tools by creating a custom action which utilises the existing authentication. (e.g.,fetch emails from Gmail) +- Extend the functionality of existing tools by creating a custom action which utilises the existing authentication. (e.g., fetch emails from Gmail) - Create standalone custom actions for any functionality you need (e.g., data processing, calculations, or integrations with other services) @@ -15,7 +15,7 @@ description: "Guide to creating Custom Actions for existing tool or new tool" Custom Actions are flexible building blocks that let you create any functionality you need - from simple calculations to complex integrations. They work seamlessly with Composio's authentication system for existing tools, or can run independently for custom logic. -## Creating a Custom Action +## Creating a Custom Action for an Existing Tool @@ -34,14 +34,15 @@ const toolset = new OpenAIToolSet({}) ```
+ - - +Below is an example of creating `my_custom_action` a custom action for the `gmail` tool. The action is designed to fetch emails from a Gmail account for the last 24 hours using the existing authentication provided by Composio. + As `gmail` toolname is already registered in Composio, `auth` dictionary will be automatically provided! -```python Custom Action - Gmail (python) +```python Python @action(toolname="gmail", requires=["example-pypi-package"]) # supports any package def my_custom_action(auth: dict, account_id: str) -> str: # Uses existing gmail auth """ @@ -81,7 +82,7 @@ def my_custom_action(auth: dict, account_id: str) -> str: # Uses existing gmail return str(response) ``` -```javascript Custom Action - Gmail (javascript) +```javascript Javascript await toolset.createAction({ actionName: "myCustomAction", toolName: "gmail", @@ -112,154 +113,137 @@ await toolset.createAction({ }); ``` - - + + +Executing the custom action without Agents (it can be used with agents too) + +```python Python +toolset.execute_action( + action=my_custom_action, + params={ + 'account_id':'me' + }, +) +``` + +```javascript JavaScript +console.log( + await toolset.executeAction( + "myCustomAction", + { accountId: "me" } + ) +) +``` + + + +Output from executing Custom Action + +```shell Output +[INFO] Logging is set to INFO, use `logging_level` argument or `COMPOSIO_LOGGING_LEVEL` change this +[INFO] Executing `GMAIL_MY_CUSTOM_ACTION` with params={'query': 'test_query'} and metadata=None connected_account_id=None +[INFO] Got response={'data': {'info': {'headers': {'Authorization': 'Bearer KEY', 'x-request-id': '2c65e8b'}, 'base_url': 'https://api.github.com', 'query_params': {}}}, 'error': None, 'successful'... +{'data': {'info': {'headers': {'Authorization': 'Bearer KEY', 'x-request-id': '2c65e8b'}, 'base_url': 'https://api.github.com', 'query_params': {}}}, 'error': None, 'successful': True} +``` + + + + +## Creating a Custom Action for a New Tool + + + + + +```python Python +from composio import ComposioToolSet, App, action + +toolset = ComposioToolSet() +``` +```javascript Javascript +import { OpenAIToolSet } from "composio-core" +import { z } from "zod" + +const toolset = new OpenAIToolSet({}) +``` + + + ```python Python @action(toolname="cow", requires=["cowsay"]) -def my_custom_action(account_id: str) -> str: +def my_custom_action(message: str) -> str: """ Cow will say whatever you want it to say. - :param account_id: Account ID, pass 'me' for default account + :param message: Message to be displayed :return greeting: Formatted message. """ import cowsay - return cowsay.get_output_string("cow", account_id) + return cowsay.get_output_string("cow", message) ``` ```javascript JavaScript await toolset.createAction({ actionName: "myCustomAction", - description: "Cow will say whatever you want it to say. This can be used to print text in cow style", + description: "Cow will say whatever you want it to say", inputParams: z.object({ - accountId: z.string() + message: z.string() }), callback: async (inputParams) => { - const accountId = inputParams.accountId; - const cowMessage = `Cow says: ${accountId}`; + const message = inputParams.message; + const cowMessage = `Cow says: ${message}`; return cowMessage; } }); ``` - - - -We can execute the custom action without Agents as well - - +Executing the custom action without Agents (it can be used with agents too) ```python Python -from composio import ComposioToolSet - -toolset = ComposioToolSet() toolset.execute_action( action=my_custom_action, - params={ - 'account_id':'me' - }, + params={"message": "AI is the future"} ) + +print(result['data']['greeting']) ``` ```javascript JavaScript console.log( await toolset.executeAction( "myCustomAction", - { accountId: "me" } + { message: "AI is the future" } ) ) ``` - - - -```python Python Executing Custom Action with Agent -from openai import OpenAI -from composio_openai import ComposioToolSet - -openai_client = OpenAI() -# Initialise the Composio Tool Set -composio_toolset = ComposioToolSet() - -# Get GitHub tools that are pre-configured -# Retrieve actions -actions = composio_toolset.get_tools(actions=[my_custom_action]) - -my_task = "Fetch emails from Gmail account for last 24 hours" - -# Setup openai assistant -assistant_instruction = "You are a super intelligent personal assistant" - -# Prepare assistant -assistant = openai_client.beta.assistants.create( - name="Personal Assistant", - instructions=assistant_instruction, - model="gpt-4-turbo-preview", - tools=actions, # type: ignore -) - -# create a thread -thread = openai_client.beta.threads.create() -message = openai_client.beta.threads.messages.create( - thread_id=thread.id, role="user", content=my_task -) - -# Execute Agent with integrations - -run = openai_client.beta.threads.runs.create( - thread_id=thread.id, assistant_id=assistant.id -) - -# Execute function calls -response_after_tool_calls = composio_toolset.wait_and_handle_assistant_tool_calls( - client=openai_client, - run=run, - thread=thread, -) - -url = f"https://platform.openai.com/playground/assistants?assistant={assistant.id}&thread={thread.id}" - -print("Visit this URL to view the thread: ", url) -``` - -```javascript Javascript Custom Action with Agent -const tools = await toolset.getTools({ actions: ["myCustomAction"] }); -const instruction = "Fetch emails from Gmail account for last 24 hours" - -const client = new OpenAI({ apiKey: process.env.OPEN_AI_API_KEY }) -const response = await client.chat.completions.create({ - model: "gpt-4-turbo", - messages: [{ - role: "user", - content: instruction, - }], - tools: tools, - tool_choice: "auto", -}) - -console.log("Result", await toolset.handleToolCall(response)); -``` - - - - -Output from executing Custom Action without Agents +Output from executing Custom Action -```shell Output from executing Custom Action without Agents -[INFO] Logging is set to INFO, use `logging_level` argument or `COMPOSIO_LOGGING_LEVEL` change this -[INFO] Executing `GMAIL_MY_CUSTOM_ACTION` with params={'query': 'test_query'} and metadata=None connected_account_id=None -[INFO] Got response={'data': {'info': {'headers': {'Authorization': 'Bearer KEY', 'x-request-id': '2c65e8b'}, 'base_url': 'https://api.github.com', 'query_params': {}}}, 'error': None, 'successful'... -{'data': {'info': {'headers': {'Authorization': 'Bearer KEY', 'x-request-id': '2c65e8b'}, 'base_url': 'https://api.github.com', 'query_params': {}}}, 'error': None, 'successful': True} +```shell Output (Python) + ________________ +| AI is the future | + ================ + \ + \ + ^__^ + (oo)\_______ + (__)\ )\/\ + ||----w | + || || +``` +```shell Output (Javascript) +Cow says: AI is the future ``` + ### Why Use Custom Actions? Custom Actions provide several advantages: From 4ce6ca09d759935071103fe1c8c3cb47dfdc3d77 Mon Sep 17 00:00:00 2001 From: abhishekpatil4 Date: Tue, 19 Nov 2024 22:04:08 +0530 Subject: [PATCH 11/25] feat: delete action-guide from Basics/Actions | moved to Tools --- .../components/actions/action-guide.mdx | 102 ------------------ docs/mint.json | 1 - 2 files changed, 103 deletions(-) delete mode 100644 docs/introduction/foundations/components/actions/action-guide.mdx diff --git a/docs/introduction/foundations/components/actions/action-guide.mdx b/docs/introduction/foundations/components/actions/action-guide.mdx deleted file mode 100644 index 523ce851b2..0000000000 --- a/docs/introduction/foundations/components/actions/action-guide.mdx +++ /dev/null @@ -1,102 +0,0 @@ ---- -title: "๐Ÿ› ๏ธ What can I do with Actions?" -sidebarTitle: "Actions" -icon: "wand-magic-sparkles" -description: "Understand more about Actions & Using Them" ---- - -### Introduction to Actions -Actions are **interfaces for interacting** with **external world** via - -1. **Tool API calls** (e.g., gmail API to send an email) -2. **System Code execution** (e.g., Python code to generate a report) - - -```python Python Fetching an Action -tools = tool_set.get_tools(actions=[Action.GITHUB_ACTIVITY_STAR_REPO_FOR_AUTHENTICATED_USER]) -``` - -```javascript JavaScript Fetching an Action -const tools = await composioToolset.getTools({ - actions: ["github_star_a_repository_for_the_authenticated_user"] -}); -``` - - - -Actions are function calling compatible which means they can be used via Agentic Frameworks or any other LLMs. - - -### Action Types - -1. **Actions to Manage External Tools**: These are actions that are pre-configured for specific tools like **Asana tool** has actions for creating tasks, adding comments, etc. -2. **Actions to Manage System**: Actions that **interact with the execution environment**, including **file systems, shell commands, and browser automation**. -3. **Custom Actions**: These are custom code actions that you write in Python, JavaScript. It can also **extend the capabilities of Composio to interact with any existing/new tools**. - -### Quick Starts - - - How to use Actions with Agentic Frameworks - - - How to use Actions without Agents - - - - How to create and use Custom Actions for existing & new tools - - - Filter actions on the basis of natural language - - - - -### Action Limits - - - Giving LLM's too many actions can lead to significant performance issues. - - ```python python - tools = tool_set.get_tools(apps=[App.ASANA]) - # Asana has 100+ actions - ``` - ```javascript javascript - const tools = toolset.getTools({ - apps: ["github"] - }) // Github has 100+ actions - ``` - - - -Empirical evidence indicates that agents perform optimally when limited to fewer than 20 actions. - -To optimize agent performance, it's essential to limit the number of actions available. This can be achieved through effective action filtering strategies. - -Here are some recommended approaches: -1. Use specific actions from a tool -2. Implement custom filtering logic - -By carefully curating the action set, you can significantly improve agent efficiency and response quality. diff --git a/docs/mint.json b/docs/mint.json index 0582b9efc3..42f8b5d747 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -91,7 +91,6 @@ "pages":[ "introduction/foundations/basic", "introduction/foundations/components/entity/entity-guide", - "introduction/foundations/components/actions/action-guide", "introduction/foundations/components/custom_actions", "introduction/foundations/components/triggers/trigger-guide", "introduction/foundations/components/integrations/custom-integration", From 2d5ecbcea375df836d84b06f0cf7f59abdfc8a55 Mon Sep 17 00:00:00 2001 From: abhishekpatil4 Date: Wed, 20 Nov 2024 00:11:46 +0530 Subject: [PATCH 12/25] feat: actions section restructuring --- docs/mint.json | 35 ++++-- .../custom-action-for-existing-tool.mdx} | 108 +---------------- .../custom-action-for-new-tool.mdx | 112 ++++++++++++++++++ .../action-guide-with-agents.mdx | 0 .../action-guide-without-agents.mdx | 2 +- .../tools/{ => use-tools}/filter-actions.mdx | 22 ---- .../tools/use-tools/use-specific-actions.mdx | 30 +++++ 7 files changed, 171 insertions(+), 138 deletions(-) rename docs/patterns/tools/{custom_actions.mdx => build-tools/custom-action-for-existing-tool.mdx} (67%) create mode 100644 docs/patterns/tools/build-tools/custom-action-for-new-tool.mdx rename docs/patterns/tools/{ => use-tools}/action-guide-with-agents.mdx (100%) rename docs/patterns/tools/{ => use-tools}/action-guide-without-agents.mdx (98%) rename docs/patterns/tools/{ => use-tools}/filter-actions.mdx (76%) create mode 100644 docs/patterns/tools/use-tools/use-specific-actions.mdx diff --git a/docs/mint.json b/docs/mint.json index 42f8b5d747..55a6648327 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -111,17 +111,6 @@ "patterns/Auth/examples/shopify_example" ] }, - { - "group":"Tools", - "icon":"shuttle-space" , - "pages":[ - "patterns/tools/what-are-tools", - "patterns/tools/action-guide-with-agents", - "patterns/tools/action-guide-without-agents", - "patterns/tools/custom_actions", - "patterns/tools/filter-actions" - ] - }, { "group": "Triggers", "icon":"bolt", @@ -144,6 +133,30 @@ } ] }, + { + "group": "Tools", + "pages": [ + "patterns/tools/what-are-tools", + { + "group": "Use Tools", + "icon": "shuttle-space", + "pages": [ + "patterns/tools/use-tools/action-guide-with-agents", + "patterns/tools/use-tools/action-guide-without-agents", + "patterns/tools/use-tools/use-specific-actions", + "patterns/tools/use-tools/filter-actions" + ] + }, + { + "group": "Build Tools/Actions", + "icon": "hammer", + "pages": [ + "patterns/tools/build-tools/custom-action-for-new-tool", + "patterns/tools/build-tools/custom-action-for-existing-tool" + ] + } + ] + }, { "group":"Supported Frameworks", "pages":[ diff --git a/docs/patterns/tools/custom_actions.mdx b/docs/patterns/tools/build-tools/custom-action-for-existing-tool.mdx similarity index 67% rename from docs/patterns/tools/custom_actions.mdx rename to docs/patterns/tools/build-tools/custom-action-for-existing-tool.mdx index 7db0ef79a0..ab5a41b993 100644 --- a/docs/patterns/tools/custom_actions.mdx +++ b/docs/patterns/tools/build-tools/custom-action-for-existing-tool.mdx @@ -1,16 +1,10 @@ --- -title: "Custom Actions" -sidebarTitle: "Build Tools" -icon: "hammer" -description: "Guide to creating Custom Actions for existing tool or new tool" +title: "Create an Action for Existing Tool" +sidebarTitle: "Create an Action for Existing Tool" +icon: "toolbox" +description: "Extend the functionality of existing tools by creating a custom action which utilises the existing authentication. (e.g., fetch emails from Gmail)" --- -## What are Custom Actions? - -- Extend the functionality of existing tools by creating a custom action which utilises the existing authentication. (e.g., fetch emails from Gmail) -- Create standalone custom actions for any functionality you need (e.g., data processing, calculations, or integrations with other services) - - Custom Actions are flexible building blocks that let you create any functionality you need - from simple calculations to complex integrations. They work seamlessly with Composio's authentication system for existing tools, or can run independently for custom logic. @@ -150,100 +144,6 @@ Output from executing Custom Action -## Creating a Custom Action for a New Tool - - - - - -```python Python -from composio import ComposioToolSet, App, action - -toolset = ComposioToolSet() -``` -```javascript Javascript -import { OpenAIToolSet } from "composio-core" -import { z } from "zod" - -const toolset = new OpenAIToolSet({}) -``` - - - - -```python Python -@action(toolname="cow", requires=["cowsay"]) -def my_custom_action(message: str) -> str: - """ - Cow will say whatever you want it to say. - - :param message: Message to be displayed - :return greeting: Formatted message. - """ - import cowsay - - return cowsay.get_output_string("cow", message) -``` -```javascript JavaScript -await toolset.createAction({ - actionName: "myCustomAction", - description: "Cow will say whatever you want it to say", - inputParams: z.object({ - message: z.string() - }), - callback: async (inputParams) => { - const message = inputParams.message; - const cowMessage = `Cow says: ${message}`; - return cowMessage; - } -}); -``` - - - -Executing the custom action without Agents (it can be used with agents too) - -```python Python -toolset.execute_action( - action=my_custom_action, - params={"message": "AI is the future"} -) - -print(result['data']['greeting']) -``` - -```javascript JavaScript -console.log( - await toolset.executeAction( - "myCustomAction", - { message: "AI is the future" } - ) -) -``` - - -Output from executing Custom Action - -```shell Output (Python) - ________________ -| AI is the future | - ================ - \ - \ - ^__^ - (oo)\_______ - (__)\ )\/\ - ||----w | - || || -``` -```shell Output (Javascript) -Cow says: AI is the future -``` - - - - - ### Why Use Custom Actions? Custom Actions provide several advantages: diff --git a/docs/patterns/tools/build-tools/custom-action-for-new-tool.mdx b/docs/patterns/tools/build-tools/custom-action-for-new-tool.mdx new file mode 100644 index 0000000000..b589af16c4 --- /dev/null +++ b/docs/patterns/tools/build-tools/custom-action-for-new-tool.mdx @@ -0,0 +1,112 @@ +--- +title: "Create a Tool" +sidebarTitle: "Create a Tool" +icon: "plus" +description: "Create standalone custom Tool and Action for any functionality you need (e.g., data processing, calculations, or integrations with other services)" +--- + + +Custom Actions are flexible building blocks that let you create any functionality you need - from simple calculations to complex integrations. They work seamlessly with Composio's authentication system for existing tools, or can run independently for custom logic. + + +## Creating a Custom Action for a New Tool + + + + + +```python Python +from composio import ComposioToolSet, App, action + +toolset = ComposioToolSet() +``` +```javascript Javascript +import { OpenAIToolSet } from "composio-core" +import { z } from "zod" + +const toolset = new OpenAIToolSet({}) +``` + + + + +```python Python +@action(toolname="cow", requires=["cowsay"]) +def my_custom_action(message: str) -> str: + """ + Cow will say whatever you want it to say. + + :param message: Message to be displayed + :return greeting: Formatted message. + """ + import cowsay + + return cowsay.get_output_string("cow", message) +``` +```javascript JavaScript +await toolset.createAction({ + actionName: "myCustomAction", + description: "Cow will say whatever you want it to say", + inputParams: z.object({ + message: z.string() + }), + callback: async (inputParams) => { + const message = inputParams.message; + const cowMessage = `Cow says: ${message}`; + return cowMessage; + } +}); +``` + + + +Executing the custom action without Agents (it can be used with agents too) + +```python Python +toolset.execute_action( + action=my_custom_action, + params={"message": "AI is the future"} +) + +print(result['data']['greeting']) +``` + +```javascript JavaScript +console.log( + await toolset.executeAction( + "myCustomAction", + { message: "AI is the future" } + ) +) +``` + + +Output from executing Custom Action + +```shell Output (Python) + ________________ +| AI is the future | + ================ + \ + \ + ^__^ + (oo)\_______ + (__)\ )\/\ + ||----w | + || || +``` +```shell Output (Javascript) +Cow says: AI is the future +``` + + + + + +### Why Use Custom Tools or Actions? + +Custom Tools or Actions provide several advantages: + +- **Data privacy:** Execution happens on the userโ€™s machine, ensuring sensitive data doesnโ€™t leave the local environment. +- **Flexibility:** Users can create and customize as many tools and actions as needed. +- **Compatibility:** Custom actions can be integrated seamlessly across various Composio-supported platforms. diff --git a/docs/patterns/tools/action-guide-with-agents.mdx b/docs/patterns/tools/use-tools/action-guide-with-agents.mdx similarity index 100% rename from docs/patterns/tools/action-guide-with-agents.mdx rename to docs/patterns/tools/use-tools/action-guide-with-agents.mdx diff --git a/docs/patterns/tools/action-guide-without-agents.mdx b/docs/patterns/tools/use-tools/action-guide-without-agents.mdx similarity index 98% rename from docs/patterns/tools/action-guide-without-agents.mdx rename to docs/patterns/tools/use-tools/action-guide-without-agents.mdx index 966ca15318..9b3a8a56a9 100644 --- a/docs/patterns/tools/action-guide-without-agents.mdx +++ b/docs/patterns/tools/use-tools/action-guide-without-agents.mdx @@ -1,5 +1,5 @@ --- -title: "๐Ÿ› ๏ธ How can I execute Actions without my AI Agent?" +title: "๐Ÿ› ๏ธ How can I execute Actions without an AI Agent?" sidebarTitle: "Use Tools without Agents" icon: "fax" description: "Perform Actions with your account or on behalf of your users without Agents" diff --git a/docs/patterns/tools/filter-actions.mdx b/docs/patterns/tools/use-tools/filter-actions.mdx similarity index 76% rename from docs/patterns/tools/filter-actions.mdx rename to docs/patterns/tools/use-tools/filter-actions.mdx index 01abfb6db9..b4fd517145 100644 --- a/docs/patterns/tools/filter-actions.mdx +++ b/docs/patterns/tools/use-tools/filter-actions.mdx @@ -7,28 +7,6 @@ description: "This documentation will guide you through the process of filtering Filtering actions is crucial for optimizing AI agent performance by narrowing down the action set to the most relevant ones. -### Selecting Actions by ID -You can select specific Actions from a given App by specifying action IDs. - -```python Python -from composio import ComposioToolSet, App, action - -toolset = ComposioToolSet() - -# can pass multiple actions -tools = toolset.get_tools(actions=[Action.GITHUB_CREATE_AN_ISSUE,Action.GITHUB_COMMIT_EVENT]) -``` - -```javascript Javascript -import { LangchainToolSet } from "composio-core"; - -const toolset = new LangchainToolSet(); - -// can pass multiple actions -const tools = await toolset.getTools({actions: ['github_issues_create','github_commit_event']}); -``` - - ### Filtering Actions by Tags Filter the Actions in an App based on tags. For example, you can: diff --git a/docs/patterns/tools/use-tools/use-specific-actions.mdx b/docs/patterns/tools/use-tools/use-specific-actions.mdx new file mode 100644 index 0000000000..9b6e8ea44e --- /dev/null +++ b/docs/patterns/tools/use-tools/use-specific-actions.mdx @@ -0,0 +1,30 @@ +--- +title: "Use Specific Actions" +sidebarTitle: "Use Specific Actions" +icon: "pickaxe" +description: "You can select specific Actions from a given App by specifying action IDs." +--- + +Specifying specific Actions is crucial for optimizing AI agent performance by narrowing down the action set to the most relevant ones. + +### Specifying Actions by ID +`GITHUB_CREATE_AN_ISSUE` and `GITHUB_COMMIT_EVENT` are action IDs for the Github Tool/App. + +```python Python +from composio import ComposioToolSet, App, action + +toolset = ComposioToolSet() + +# can pass multiple actions +tools = toolset.get_tools(actions=[Action.GITHUB_CREATE_AN_ISSUE,Action.GITHUB_COMMIT_EVENT]) +``` + +```javascript Javascript +import { LangchainToolSet } from "composio-core"; + +const toolset = new LangchainToolSet(); + +// can pass multiple actions +const tools = await toolset.getTools({actions: ['github_issues_create','github_commit_event']}); +``` + \ No newline at end of file From 57f979e2c1dc1824a79b012530b1669b8d92668c Mon Sep 17 00:00:00 2001 From: abhishekpatil4 Date: Wed, 20 Nov 2024 10:44:23 +0530 Subject: [PATCH 13/25] minor change --- docs/mint.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/mint.json b/docs/mint.json index 55a6648327..6bb1d19f30 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -187,7 +187,7 @@ ] }, { - "group": "SweKit", + "group": "SWE Kit", "pages": [ "swekit-tools/introduction", "swekit-js/introduction", From 5725cf9ac1990bc1d194fd7135ee700aacb1be42 Mon Sep 17 00:00:00 2001 From: abhishekpatil4 Date: Wed, 20 Nov 2024 10:45:41 +0530 Subject: [PATCH 14/25] minor change --- docs/swekit/benchmarks.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/swekit/benchmarks.mdx b/docs/swekit/benchmarks.mdx index 53ee5d606d..3a693b4687 100644 --- a/docs/swekit/benchmarks.mdx +++ b/docs/swekit/benchmarks.mdx @@ -1,6 +1,6 @@ --- title: "Benchmarks" -sidebarTitle: "SweKit Benchmarks" +sidebarTitle: "SWE Kit Benchmarks" icon: "chart-line" description: "Learn how to run and evaluate your SWE agents using benchmarks" --- From ce39a4db2727a538f77bbda7392a94c80aa296e4 Mon Sep 17 00:00:00 2001 From: abhishekpatil4 Date: Wed, 20 Nov 2024 15:44:47 +0530 Subject: [PATCH 15/25] feat: add 'get-action-inputs' page --- docs/mint.json | 3 +- .../use-tools/action-guide-without-agents.mdx | 64 +------------------ .../tools/use-tools/get-action-inputs.mdx | 64 +++++++++++++++++++ docs/patterns/tools/what-are-tools.mdx | 4 +- 4 files changed, 69 insertions(+), 66 deletions(-) create mode 100644 docs/patterns/tools/use-tools/get-action-inputs.mdx diff --git a/docs/mint.json b/docs/mint.json index 6bb1d19f30..29d9424902 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -144,11 +144,12 @@ "patterns/tools/use-tools/action-guide-with-agents", "patterns/tools/use-tools/action-guide-without-agents", "patterns/tools/use-tools/use-specific-actions", + "patterns/tools/use-tools/get-action-inputs", "patterns/tools/use-tools/filter-actions" ] }, { - "group": "Build Tools/Actions", + "group": "Build Tools", "icon": "hammer", "pages": [ "patterns/tools/build-tools/custom-action-for-new-tool", diff --git a/docs/patterns/tools/use-tools/action-guide-without-agents.mdx b/docs/patterns/tools/use-tools/action-guide-without-agents.mdx index 9b3a8a56a9..4c73f6fce3 100644 --- a/docs/patterns/tools/use-tools/action-guide-without-agents.mdx +++ b/docs/patterns/tools/use-tools/action-guide-without-agents.mdx @@ -7,69 +7,7 @@ description: "Perform Actions with your account or on behalf of your users witho ## Using Actions -Composio lets you perform actions with your account or on behalf of your users. When executing actions without agents, you'll need to provide the required parameters. There are two ways to obtain these parameters: - -1. Through the [API Section](/api-reference/actions/get-action) of our documentation -2. Programmatically using our SDK - -Feel free to check all the [tools](https://app.composio.dev/apps) we support. - -### Get Parameters for an Action - -Below are demonstrations of both methods to get the parameters for an action: - -#### Using the [API Section](/api-reference/actions/get-action) from the Documentation - - -1. Navigate to the [API Section](/api-reference/actions/get-action) of our documentation -2. Click on **Get Action** under the **Actions** category -3. Enter your Composio API key and the Action ID -4. The **parameters** attribute in the response contains the required parameters for executing the action - - -#### Using the SDK - - ```python Python -from composio import ComposioToolSet, Action -import json - -composio_toolset = ComposioToolSet() - -# Get the action schema -action_schema = composio_toolset.get_action_schemas(actions=[Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER]) - -# Print the parameters in a readable format -print(json.dumps(action_schema[0].parameters.properties, indent=2)) -``` - -```javascript Javascript -import { OpenAIToolSet } from "composio-core"; - -const composio_toolset = new OpenAIToolSet(); - -const schema = await composio_toolset.getActionsSchema({ - actions: ["github_star_a_repository_for_the_authenticated_user"], -}); - -console.log(JSON.stringify(schema[0].parameters.properties, null, 2)); - ``` - - -```bash Output -{ - "owner": { - "description": "The account owner of the repository. The name is not case sensitive. Please provide a value of type string. This parameter is required.", - "title": "Owner", - "type": "string" - }, - "repo": { - "description": "The name of the repository without the `.git` extension. The name is not case sensitive. . Please provide a value of type string. This parameter is required.", - "title": "Repo", - "type": "string" - } -} -``` - +Composio lets you perform actions with your account or on behalf of your users. When executing actions without agents, you'll need to provide the input parameters. Checkout [Get Action Inputs](/patterns/tools/use-tools/get-action-inputs) to learn how to get the input parameters for an action. ### Execute Actions without Agents diff --git a/docs/patterns/tools/use-tools/get-action-inputs.mdx b/docs/patterns/tools/use-tools/get-action-inputs.mdx new file mode 100644 index 0000000000..ebd4d3c435 --- /dev/null +++ b/docs/patterns/tools/use-tools/get-action-inputs.mdx @@ -0,0 +1,64 @@ +--- +title: "๐Ÿ› ๏ธ How can I get the input parameters for an Action?" +sidebarTitle: "Get Action Inputs" +icon: "text-size" +description: "Get the input parameters for an Action" +--- + +### When will I need to provide input parameters? +When executing actions without agents, you'll need to provide the input parameters. There are two ways to obtain these parameters: + +1. Through the [API Section](/api-reference/actions/get-action) of our documentation +2. Programmatically using our SDK + +### Using the [API Section](/api-reference/actions/get-action) from the Documentation + + +1. Navigate to the [API Section](/api-reference/actions/get-action) of our documentation +2. Click on **Get Action** under the **Actions** category +3. Enter your Composio API key and the Action ID +4. The **parameters** attribute in the response contains the required parameters for executing the action + + +### Using the SDK + + ```python Python +from composio import ComposioToolSet, Action +import json + +composio_toolset = ComposioToolSet() + +# Get the action schema +action_schema = composio_toolset.get_action_schemas(actions=[Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER]) + +# Print the parameters in a readable format +print(json.dumps(action_schema[0].parameters.properties, indent=2)) +``` + +```javascript Javascript +import { OpenAIToolSet } from "composio-core"; + +const composio_toolset = new OpenAIToolSet(); + +const schema = await composio_toolset.getActionsSchema({ + actions: ["github_star_a_repository_for_the_authenticated_user"], +}); + +console.log(JSON.stringify(schema[0].parameters.properties, null, 2)); + ``` + + +```bash Output +{ + "owner": { + "description": "The account owner of the repository. The name is not case sensitive. Please provide a value of type string. This parameter is required.", + "title": "Owner", + "type": "string" + }, + "repo": { + "description": "The name of the repository without the `.git` extension. The name is not case sensitive. . Please provide a value of type string. This parameter is required.", + "title": "Repo", + "type": "string" + } +} +``` \ No newline at end of file diff --git a/docs/patterns/tools/what-are-tools.mdx b/docs/patterns/tools/what-are-tools.mdx index 6a13bbd720..de7e285a14 100644 --- a/docs/patterns/tools/what-are-tools.mdx +++ b/docs/patterns/tools/what-are-tools.mdx @@ -1,6 +1,6 @@ --- -title: "๐Ÿ› ๏ธ What are Tools/Actions?" -sidebarTitle: "What are Tools/Actions?" +title: "๐Ÿ› ๏ธ What are Tools & Actions?" +sidebarTitle: "What are Tools?" icon: "question" description: "Learn about tools in Composio" --- From 90ca8a3e87f25e34fc902ce3c3393218cce98615 Mon Sep 17 00:00:00 2001 From: abhishekpatil4 Date: Wed, 20 Nov 2024 17:40:49 +0530 Subject: [PATCH 16/25] feat: update processing page --- .../foundations/components/custom_actions.mdx | 80 ------------------- docs/mint.json | 3 +- .../tools/use-tools/processing-actions.mdx} | 31 ++++++- 3 files changed, 28 insertions(+), 86 deletions(-) delete mode 100644 docs/introduction/foundations/components/custom_actions.mdx rename docs/{introduction/foundations/components/actions/processing.mdx => patterns/tools/use-tools/processing-actions.mdx} (74%) diff --git a/docs/introduction/foundations/components/custom_actions.mdx b/docs/introduction/foundations/components/custom_actions.mdx deleted file mode 100644 index 6c066baa31..0000000000 --- a/docs/introduction/foundations/components/custom_actions.mdx +++ /dev/null @@ -1,80 +0,0 @@ ---- -title: "Creating a Custom Action" -sidebarTitle: "Custom Actions" -icon: "gear" -description: "Complete customisation by creating your own actions" ---- - -## Overview - -**Custom Actions** in Composio allow users to execute actions locally, enhancing privacy and customization. - -Composio supports two action types: - -1. **Composio-Managed Actions:** Available on the [dashboard](https://app.composio.dev/). -2. **Custom Actions:** Defined and executed locally or in the tool [workspace](/introduction/foundations/components/workspace). - -**Custom actions** can be defined for **existing tools (gmail, google_calendar, etc.) or for your own tools.** - -```python Python Defining Custom Action -from composio import action - -@action(toolname="cow", requires=["cowsay"]) -def say(message: str) -> str: - """ - Cow will say whatever you want it to say. - - :param message: Message string - :return greeting: Formatted message. - """ - # A Description needs to be added to each Custom Action function - # The format is: - # """ - # description line - # :param input_param_1: input_param_description - # :param input_param_2: input_param_2_description - # :return output_variable: output_variable_description - # """ - import cowsay - - return cowsay.get_output_string("cow", message) -``` -```javascript Javascript Defining Custom Action -import { z } from "zod"; -import { ComposioToolSet } from "composio-core"; - -const toolset = new ComposioToolSet({}); - -(async () => { - await toolset.createAction({ - actionName: "sayHello", - toolName: "greetings", - description: "A simple action that says hello to someone", - inputParams: z.object({ - name: z.string().describe("Name of the person to greet") - }), - callback: async (inputParams) => { - return { - message: `Hello ${inputParams.name}!` - }; - } - }); - - const result = await toolset.executeAction("sayHello", { name: "World" }); - console.log("Action result:", result); // Will print: { message: "Hello World!" } -})(); -``` - -In this example, we **create a custom tool called "cow"** that uses the **`cowsay` library** to **output a message**. - -### Quick Starts - - - Learn more about creating a custom action for existing tools (gmail, google_calendar, etc.) & using it in your agent - diff --git a/docs/mint.json b/docs/mint.json index 29d9424902..fa994af6ae 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -91,11 +91,9 @@ "pages":[ "introduction/foundations/basic", "introduction/foundations/components/entity/entity-guide", - "introduction/foundations/components/custom_actions", "introduction/foundations/components/triggers/trigger-guide", "introduction/foundations/components/integrations/custom-integration", "introduction/foundations/components/integrations/integration-guide", - "introduction/foundations/components/actions/processing", "introduction/foundations/components/workspace", "introduction/foundations/components/list_local_tools" ] @@ -145,6 +143,7 @@ "patterns/tools/use-tools/action-guide-without-agents", "patterns/tools/use-tools/use-specific-actions", "patterns/tools/use-tools/get-action-inputs", + "patterns/tools/use-tools/processing-actions", "patterns/tools/use-tools/filter-actions" ] }, diff --git a/docs/introduction/foundations/components/actions/processing.mdx b/docs/patterns/tools/use-tools/processing-actions.mdx similarity index 74% rename from docs/introduction/foundations/components/actions/processing.mdx rename to docs/patterns/tools/use-tools/processing-actions.mdx index f7c3dc58e6..387af0d30f 100644 --- a/docs/introduction/foundations/components/actions/processing.mdx +++ b/docs/patterns/tools/use-tools/processing-actions.mdx @@ -5,6 +5,11 @@ icon: "wand-magic-sparkles" description: "Master the art of preprocessing, postprocessing, and schema processing for optimal results." --- +## Metadata + +The `metadata` in the `ComposioToolSet` configuration is used to add metadata for different Apps/Tools and Actions. e.g., session IDs, agent IDs or API keys. This allows for flexible and dynamic configuration of tools and actions within the Composio framework, ensuring that critical data are reliably passed. + + ## Refining Action Inputs, Outputs & Schemas In many scenarios, the raw inputs, outputs, or schemas of actions may benefit from additional processing. This refinement step can significantly improve the quality and usability of your data. Here are three key use cases: @@ -13,7 +18,7 @@ In many scenarios, the raw inputs, outputs, or schemas of actions may benefit fr - **Postprocessing**: Streamline large action responses by filtering or formatting the data before it reaches the Language Model (LLM). - **Schema Processing**: Modify the request schema to include additional fields or alter existing ones. -Composio empowers you with the ability to define **custom Python functions** as preprocessors, postprocessors, or schema processors. +Composio empowers you with the ability to define **custom functions** as preprocessors, postprocessors, or schema processors. These can be applied at two levels: @@ -24,7 +29,7 @@ Here's how you can implement these processors: -```python Define the Preprocessor, Postprocessor, and Schema Processor Functions +```python Python def tool_schema_processor(schema): # Modify schema as needed return modified_schema @@ -49,13 +54,28 @@ def action_postprocessor(output_data): # Process output_data as needed return processed_output_data ``` + +``` javascript JavaScript +coming soon! +``` -```python Set the schema, pre, and post processors while creating the toolset -# While defining the toolset, you can define the schema, pre, and post processors +```python Python +# While defining the toolset, you can define the metadata, schema, pre, and post processors composio_toolset = ComposioToolSet( + metadata={ + App.FILETOOL: { + "app": "filetool", + }, + Action.GREPTILE_CODE_QUERY: { + "sessionId": "....", + }, + Action.LINEAR_CREATE_LINEAR_ISSUE: { + "project_id": "...", + }, + }, processors={ "schema": { App.GITHUB: tool_schema_processor, @@ -74,6 +94,9 @@ composio_toolset = ComposioToolSet( tools = composio_toolset.get_tools(apps=[App.GITHUB]) ``` +``` javascript JavaScript +coming soon! +``` From 186fc748a718d089bc3412498936698dfda35304 Mon Sep 17 00:00:00 2001 From: abhishekpatil4 Date: Thu, 21 Nov 2024 09:57:14 +0530 Subject: [PATCH 17/25] fix: move adding custom tool page --- docs/mint.json | 1 + .../tools/build-tools/custom-action-for-existing-tool.mdx | 4 ++-- .../patterns/tools/build-tools/custom-action-for-new-tool.mdx | 4 ++-- .../tools/build-tools}/custom-integration.mdx | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) rename docs/{introduction/foundations/components/integrations => patterns/tools/build-tools}/custom-integration.mdx (99%) diff --git a/docs/mint.json b/docs/mint.json index fa994af6ae..992898b300 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -151,6 +151,7 @@ "group": "Build Tools", "icon": "hammer", "pages": [ + "patterns/tools/build-tools/custom-integration", "patterns/tools/build-tools/custom-action-for-new-tool", "patterns/tools/build-tools/custom-action-for-existing-tool" ] diff --git a/docs/patterns/tools/build-tools/custom-action-for-existing-tool.mdx b/docs/patterns/tools/build-tools/custom-action-for-existing-tool.mdx index ab5a41b993..c50a3a04a0 100644 --- a/docs/patterns/tools/build-tools/custom-action-for-existing-tool.mdx +++ b/docs/patterns/tools/build-tools/custom-action-for-existing-tool.mdx @@ -1,6 +1,6 @@ --- -title: "Create an Action for Existing Tool" -sidebarTitle: "Create an Action for Existing Tool" +title: "Create an Action for existing Tool" +sidebarTitle: "Create an Action for existing Tool" icon: "toolbox" description: "Extend the functionality of existing tools by creating a custom action which utilises the existing authentication. (e.g., fetch emails from Gmail)" --- diff --git a/docs/patterns/tools/build-tools/custom-action-for-new-tool.mdx b/docs/patterns/tools/build-tools/custom-action-for-new-tool.mdx index b589af16c4..a5ea6a8b50 100644 --- a/docs/patterns/tools/build-tools/custom-action-for-new-tool.mdx +++ b/docs/patterns/tools/build-tools/custom-action-for-new-tool.mdx @@ -1,6 +1,6 @@ --- -title: "Create a Tool" -sidebarTitle: "Create a Tool" +title: "Create an Action for new Tool" +sidebarTitle: "Create an Action for new Tool" icon: "plus" description: "Create standalone custom Tool and Action for any functionality you need (e.g., data processing, calculations, or integrations with other services)" --- diff --git a/docs/introduction/foundations/components/integrations/custom-integration.mdx b/docs/patterns/tools/build-tools/custom-integration.mdx similarity index 99% rename from docs/introduction/foundations/components/integrations/custom-integration.mdx rename to docs/patterns/tools/build-tools/custom-integration.mdx index f84d5708db..c08b5fac66 100644 --- a/docs/introduction/foundations/components/integrations/custom-integration.mdx +++ b/docs/patterns/tools/build-tools/custom-integration.mdx @@ -1,6 +1,6 @@ --- title: "๐Ÿ”ง Adding Custom Tools" -sidebarTitle: "Custom Tools" +sidebarTitle: "Adding Custom Tools" icon: "puzzle-piece" description: "Explore the process of creating custom tools with external Apps using OpenAPI Spec" --- From 926e79c218d4070f649309d06c867a4bf1547eda Mon Sep 17 00:00:00 2001 From: abhishekpatil4 Date: Thu, 21 Nov 2024 13:47:27 +0530 Subject: [PATCH 18/25] fix: broken links --- docs/introduction/foundations/basic.mdx | 4 ++-- docs/introduction/intro/quickstart.mdx | 4 ++-- docs/introduction/intro/quickstart_3.mdx | 2 +- docs/introduction/intro/quickstart_3_backup.mdx | 2 +- docs/mint.json | 1 - docs/patterns/tools/build-tools/custom-integration.mdx | 1 - 6 files changed, 6 insertions(+), 8 deletions(-) diff --git a/docs/introduction/foundations/basic.mdx b/docs/introduction/foundations/basic.mdx index 24a3f9a257..cda4a14b30 100644 --- a/docs/introduction/foundations/basic.mdx +++ b/docs/introduction/foundations/basic.mdx @@ -10,8 +10,8 @@ description: "Core Platform Modules" Learn how to manage users and authentication, integrations! - -Learn how to use, execute, process and even create actions! + +Learn how to use, execute, process and even create tools! diff --git a/docs/introduction/intro/quickstart.mdx b/docs/introduction/intro/quickstart.mdx index 4c71808bd3..2265be9977 100644 --- a/docs/introduction/intro/quickstart.mdx +++ b/docs/introduction/intro/quickstart.mdx @@ -99,7 +99,7 @@ Turn natural language into GitHub actions in minutes. Follow these 5 steps to st ```
- Composio also supports action executions without LLMs or agents. [Learn more](/patterns/actions/). + Composio also supports action executions without LLMs or agents. [Learn more](../../patterns/tools/use-tools/action-guide-without-agents). @@ -205,7 +205,7 @@ Turn natural language into GitHub actions in minutes. Follow these 5 steps to st ``` - Composio also supports action executions without LLMs or agents. [Learn more](/patterns/actions/). + Composio also supports action executions without LLMs or agents. [Learn more](../../patterns/tools/use-tools/action-guide-without-agents). diff --git a/docs/introduction/intro/quickstart_3.mdx b/docs/introduction/intro/quickstart_3.mdx index 96ac8d0655..cf5e539434 100644 --- a/docs/introduction/intro/quickstart_3.mdx +++ b/docs/introduction/intro/quickstart_3.mdx @@ -283,7 +283,7 @@ Integrate with popular agentic frameworks Authorize a user's account to perform actions and subscribe to triggers - + Execute actions on behalf of a user diff --git a/docs/introduction/intro/quickstart_3_backup.mdx b/docs/introduction/intro/quickstart_3_backup.mdx index a2bc1acf65..453a01bc35 100644 --- a/docs/introduction/intro/quickstart_3_backup.mdx +++ b/docs/introduction/intro/quickstart_3_backup.mdx @@ -278,7 +278,7 @@ Congratulations! You've just: Authorize a user's account to perform actions and subscribe to triggers - + Execute actions on behalf of a user diff --git a/docs/mint.json b/docs/mint.json index 992898b300..0339c6b845 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -92,7 +92,6 @@ "introduction/foundations/basic", "introduction/foundations/components/entity/entity-guide", "introduction/foundations/components/triggers/trigger-guide", - "introduction/foundations/components/integrations/custom-integration", "introduction/foundations/components/integrations/integration-guide", "introduction/foundations/components/workspace", "introduction/foundations/components/list_local_tools" diff --git a/docs/patterns/tools/build-tools/custom-integration.mdx b/docs/patterns/tools/build-tools/custom-integration.mdx index c08b5fac66..e69f265602 100644 --- a/docs/patterns/tools/build-tools/custom-integration.mdx +++ b/docs/patterns/tools/build-tools/custom-integration.mdx @@ -36,7 +36,6 @@ Here's a tutorial showing how to create a Custom Tool for Notion Create an `integrations.yaml` file. Below is the base template for the Integrations.yaml file for any custom tool that you create. However, you will modify the auth schems as each tool supports differnt auth methods. - For more details on how to configure the `integrations.yaml` file, refer to the [Integration YAML Configuration Guide](./integration-yaml). ```yaml From abf24bab7894db30a161dea0cacc528509fe5d47 Mon Sep 17 00:00:00 2001 From: abhishekpatil4 Date: Fri, 22 Nov 2024 00:17:02 +0530 Subject: [PATCH 19/25] feat: add modify actions/apps page | fix: minor changes --- docs/mint.json | 7 +- .../custom-action-for-existing-tool.mdx | 4 +- .../custom-action-for-new-tool.mdx | 4 +- .../{build-tools => }/custom-integration.mdx | 12 +- .../use-tools/action-guide-with-agents.mdx | 118 +++---- .../use-tools/action-guide-without-agents.mdx | 20 +- .../tools/use-tools/configure-tools.mdx | 106 +++++++ .../tools/use-tools/filter-actions.mdx | 86 ------ .../tools/use-tools/get-action-inputs.mdx | 35 ++- .../tools/use-tools/processing-actions.mdx | 291 ++++++++++++++---- .../tools/use-tools/processing-old.mdx | 106 +++++++ .../tools/use-tools/use-specific-actions.mdx | 97 +++++- 12 files changed, 641 insertions(+), 245 deletions(-) rename docs/patterns/tools/{build-tools => }/custom-integration.mdx (95%) create mode 100644 docs/patterns/tools/use-tools/configure-tools.mdx delete mode 100644 docs/patterns/tools/use-tools/filter-actions.mdx create mode 100644 docs/patterns/tools/use-tools/processing-old.mdx diff --git a/docs/mint.json b/docs/mint.json index 0339c6b845..6cc581badf 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -139,22 +139,21 @@ "icon": "shuttle-space", "pages": [ "patterns/tools/use-tools/action-guide-with-agents", - "patterns/tools/use-tools/action-guide-without-agents", "patterns/tools/use-tools/use-specific-actions", "patterns/tools/use-tools/get-action-inputs", "patterns/tools/use-tools/processing-actions", - "patterns/tools/use-tools/filter-actions" + "patterns/tools/use-tools/action-guide-without-agents" ] }, { "group": "Build Tools", "icon": "hammer", "pages": [ - "patterns/tools/build-tools/custom-integration", "patterns/tools/build-tools/custom-action-for-new-tool", "patterns/tools/build-tools/custom-action-for-existing-tool" ] - } + }, + "patterns/tools/custom-integration" ] }, { diff --git a/docs/patterns/tools/build-tools/custom-action-for-existing-tool.mdx b/docs/patterns/tools/build-tools/custom-action-for-existing-tool.mdx index c50a3a04a0..0be597a977 100644 --- a/docs/patterns/tools/build-tools/custom-action-for-existing-tool.mdx +++ b/docs/patterns/tools/build-tools/custom-action-for-existing-tool.mdx @@ -1,6 +1,6 @@ --- -title: "Create an Action for existing Tool" -sidebarTitle: "Create an Action for existing Tool" +title: "Build an Action for existing Tool" +sidebarTitle: "Build an Action for existing Tool" icon: "toolbox" description: "Extend the functionality of existing tools by creating a custom action which utilises the existing authentication. (e.g., fetch emails from Gmail)" --- diff --git a/docs/patterns/tools/build-tools/custom-action-for-new-tool.mdx b/docs/patterns/tools/build-tools/custom-action-for-new-tool.mdx index a5ea6a8b50..85fb58ff72 100644 --- a/docs/patterns/tools/build-tools/custom-action-for-new-tool.mdx +++ b/docs/patterns/tools/build-tools/custom-action-for-new-tool.mdx @@ -1,6 +1,6 @@ --- -title: "Create an Action for new Tool" -sidebarTitle: "Create an Action for new Tool" +title: "Build an Action for new Tool" +sidebarTitle: "Build an Action for new Tool" icon: "plus" description: "Create standalone custom Tool and Action for any functionality you need (e.g., data processing, calculations, or integrations with other services)" --- diff --git a/docs/patterns/tools/build-tools/custom-integration.mdx b/docs/patterns/tools/custom-integration.mdx similarity index 95% rename from docs/patterns/tools/build-tools/custom-integration.mdx rename to docs/patterns/tools/custom-integration.mdx index e69f265602..9b753668e0 100644 --- a/docs/patterns/tools/build-tools/custom-integration.mdx +++ b/docs/patterns/tools/custom-integration.mdx @@ -1,8 +1,8 @@ --- -title: "๐Ÿ”ง Adding Custom Tools" -sidebarTitle: "Adding Custom Tools" +title: "๐Ÿ”ง How to build Apps?" +sidebarTitle: "Build Apps" icon: "puzzle-piece" -description: "Explore the process of creating custom tools with external Apps using OpenAPI Spec" +description: "Learn how to create custom tools with external Apps using OpenAPI Spec" --- Creating custom tools on Composio is straightforward and can be done via an [OpenAPI Spec](https://swagger.io/specification/). @@ -34,7 +34,7 @@ Here's a tutorial showing how to create a Custom Tool for Notion - Create an `integrations.yaml` file. Below is the base template for the Integrations.yaml file for any custom tool that you create. However, you will modify the auth schems as each tool supports differnt auth methods. + Create an `integrations.yaml` file. Below is the base template for the Integrations.yaml file for any custom tool that you create. However, you will modify the auth schemes as each tool supports different auth methods. @@ -296,8 +296,8 @@ You need to add the relevant scopes as needed. Now that you have the `integratio - Go to the tools page on Composio - Click on the **Setup a New Tool** section - Upload the Open API Spec file and the `integrations.yaml` file. -- Click on the "Start import" button to test. -- Once the tests are successfully, you will be able to access this tool. +- Click on the "Start import" button to begin testing. +- Once the tests pass successfully, you will be able to access this tool. diff --git a/docs/patterns/tools/use-tools/action-guide-with-agents.mdx b/docs/patterns/tools/use-tools/action-guide-with-agents.mdx index efb286027a..9afd4e44ee 100644 --- a/docs/patterns/tools/use-tools/action-guide-with-agents.mdx +++ b/docs/patterns/tools/use-tools/action-guide-with-agents.mdx @@ -1,71 +1,75 @@ --- -title: "๐Ÿ› ๏ธ How can I execute Actions with my AI Agent?" -sidebarTitle: "Use Tools with Agents" +title: "๐Ÿ› ๏ธ How can I use Tools with LLMs?" +sidebarTitle: "Use Tools with LLMs" icon: "robot" -description: "Perform Actions with your account or on behalf of your users with Agents" +description: "Guide to using Tools with LLMs" --- -## Using Actions -Composio lets you perform actions with your account or on behalf of your users. Feel free to check all the [tools](https://app.composio.dev/apps) we support. +### Using Tools with LLMs -### Execute Actions with Agents - -To execute actions with your account or on behalf of your users, you can use the following code. +Composio enables you to integrate various tools (like Gmail, GitHub, Salesforce) and perform actions (such as sending emails or creating GitHub issues). Browse our complete list of supported [Tools](https://app.composio.dev/apps). +Here's how you can use Apps with LLMs: ```python Python -from langchain.agents import create_openai_functions_agent, AgentExecutor -from langchain import hub -from langchain_openai import ChatOpenAI -from composio_langchain import ComposioToolSet, Action, App -import os - - -llm = ChatOpenAI(model="gpt-4o") - -prompt = hub.pull("hwchase17/openai-functions-agent") - -# Get All the tools -tool_set = ComposioToolSet() -tools = tool_set.get_tools(actions=[Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER], tags=[]) - -# Define task -task = "Star a repo composiohq/composio on GitHub" - -agent = create_openai_functions_agent(llm, tools, prompt) -agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True) - -# Execute using agent_executor -agent_executor.invoke({"input": task}) +# Import required libraries +from composio_openai import ComposioToolSet, App +from openai import OpenAI + +# Initialize OpenAI and Composio clients +openai_client = OpenAI() +composio_toolset = ComposioToolSet() + +# Get GitHub tools from Composio +tools = composio_toolset.get_tools(apps=[App.GITHUB]) + +task = "Star the repo composiohq/composio on GitHub" + +# Make API call to OpenAI with the tools +response = openai_client.chat.completions.create( + model="gpt-4o-mini", + tools=tools, + messages=[ + {"role": "system", "content": "You are a helpful assistant."}, + {"role": "user", "content": task}, + ], +) + +# Execute the tool calls +result = composio_toolset.handle_tool_calls(response) +print(result) ``` ```javascript JavaScript - import { LangchainToolSet } from "composio-core"; - import { ChatOpenAI } from "@langchain/openai"; - import { AgentExecutor, createOpenAIFunctionsAgent } from "langchain/agents"; - import { pull } from "langchain/hub"; - - - (async () => { - const llm = new ChatOpenAI({ model: "gpt-4-turbo" }); - const composioToolset = new LangchainToolSet({ apiKey: process.env.COMPOSIO_API_KEY }); - const tools = await composioToolset.getTools({ actions: ["github_issues_create"] }); - const prompt = await pull("hwchase17/openai-functions-agent"); - - const agent = await createOpenAIFunctionsAgent({ llm, tools, prompt }); - const agentExecutor = new AgentExecutor({ agent, tools, verbose: true }); - const issueDetails = { - TITLE: "Sample issue", - DESCRIPTION: "Sample issue for the repo - himanshu-dixit/custom-repo-breaking" - }; - - const result = await agentExecutor.invoke({ - input: `Create a GitHub issue with the following details: ${JSON.stringify(issueDetails)}` - }); - return result.output; - })(); +// Import required libraries +import { OpenAI } from "openai"; +import { OpenAIToolSet } from "composio-core"; + +// Initialize OpenAI and Composio clients +const openai_client = new OpenAI(); +const composio_toolset = new OpenAIToolSet(); + +// Get GitHub tools from Composio +const tools = await composio_toolset.getTools({ + actions: ["github_star_a_repository_for_the_authenticated_user"] +}); + +const task = "Star the repo composiohq/composio on GitHub"; + +// Make API call to OpenAI with the tools +const response = await openai_client.chat.completions.create({ + model: "gpt-4o-mini", + messages: [{ role: "user", content: task }], + tools: tools, + tool_choice: "auto", +}); + +// Execute the tool calls +const result = await composio_toolset.handleToolCall(response); +console.log(result); ``` -This code demonstrates how to use LLMs to execute an action. -Composio supports multiple frameworks for creating Agents including LlamaIndex, CrewAI, Letta, LangChain, you can see it in the **Supported Frameworks** section. +This code demonstrates how to use LLMs with Composio Tools to execute actions. The example shows how to connect OpenAI's LLM with Composio's tools - in this case, using GitHub tool. The LLM understands the natural language task ("Star the repo") and determines which action to use from Github tool, then executes the action. + +Composio supports multiple agent frameworks including LlamaIndex, CrewAI, Letta, and LangChain. See the [**Supported Frameworks**](../../../framework) section for details. diff --git a/docs/patterns/tools/use-tools/action-guide-without-agents.mdx b/docs/patterns/tools/use-tools/action-guide-without-agents.mdx index 4c73f6fce3..324c633b3f 100644 --- a/docs/patterns/tools/use-tools/action-guide-without-agents.mdx +++ b/docs/patterns/tools/use-tools/action-guide-without-agents.mdx @@ -1,17 +1,13 @@ --- -title: "๐Ÿ› ๏ธ How can I execute Actions without an AI Agent?" -sidebarTitle: "Use Tools without Agents" +title: "๐Ÿ› ๏ธ How can I use Tools directly?" +sidebarTitle: "Use Tools Directly" icon: "fax" -description: "Perform Actions with your account or on behalf of your users without Agents" +description: "Guide to using Tools directly like calling a function" --- -## Using Actions +### Using Tools Directly -Composio lets you perform actions with your account or on behalf of your users. When executing actions without agents, you'll need to provide the input parameters. Checkout [Get Action Inputs](/patterns/tools/use-tools/get-action-inputs) to learn how to get the input parameters for an action. - -### Execute Actions without Agents - -To execute actions without using Agents, you can manually supply the parameters to execute the action or use natural language. +Composio lets you use tools directly like calling a function. When calling a tool directly, you'll need to provide the input parameters. Checkout [Get Action Schema](/patterns/tools/use-tools/get-action-inputs) to learn how to get the input parameters for an action. ```python Python Star a repo @@ -53,13 +49,14 @@ console.log("Custom auth action response", customAuthAction) ``` -### Execute Actions with Natural Language -You can also execute Actions by passing in natural language prompts without specific parameters +### Execute Tools or Actions with Natural Language +You can also execute Tools or Actions by passing in natural language prompts without specific parameters ```python Python tool_set.execute_action( action=Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER, params={}, + # Natural language prompt text="Star the repo composiohq/composio", entity_id="Jessica", ) @@ -69,6 +66,7 @@ You can also execute Actions by passing in natural language prompts without spec await toolset.getEntity("Jessica").execute( 'github_star_a_repository_for_the_authenticated_user', {}, + // Natural language prompt "Star the repo composiohq/composio" ); ``` diff --git a/docs/patterns/tools/use-tools/configure-tools.mdx b/docs/patterns/tools/use-tools/configure-tools.mdx new file mode 100644 index 0000000000..ee335e7929 --- /dev/null +++ b/docs/patterns/tools/use-tools/configure-tools.mdx @@ -0,0 +1,106 @@ +--- +title: "๐Ÿ› ๏ธ Configure Tools" +sidebarTitle: "Configure Tools" +icon: "wand-magic-sparkles" +description: "Learn how to configure tools" +--- + +## Metadata + +The `metadata` in the `ComposioToolSet` configuration is used to add metadata for different Apps/Tools and Actions. e.g., session IDs, agent IDs or API keys. This allows for flexible and dynamic configuration of tools and actions within the Composio framework, ensuring that critical data are reliably passed. + + +## Refining Action Inputs, Outputs & Schemas + +In many scenarios, the raw inputs, outputs, or schemas of actions may benefit from additional processing. This refinement step can significantly improve the quality and usability of your data. Here are three key use cases: + +- **Preprocessing**: Generate or modify inputs dynamically at runtime, handling scenarios that may be challenging for the LLM to produce directly. +- **Postprocessing**: Streamline large action responses by filtering or formatting the data before it reaches the Language Model (LLM). +- **Schema Processing**: Modify the request schema to include additional fields or alter existing ones. + +Composio empowers you with the ability to define **custom functions** as preprocessors, postprocessors, or schema processors. + +These can be applied at two levels: + +1. **Tool-level**: Affects all actions within a specific tool. +2. **Action-level**: Tailored processing for individual actions. + +Here's how you can implement these processors: + + + +```python Python +def tool_schema_processor(schema): + # Modify schema as needed + return modified_schema + +def tool_preprocessor(input_data): + # Modify input_data as needed + return modified_input_data + +def tool_postprocessor(output_data): + # Process output_data as needed + return processed_output_data + +def action_schema_processor(schema): + # Modify schema as needed + return modified_schema + +def action_preprocessor(input_data): + # Modify input_data as needed + return modified_input_data + +def action_postprocessor(output_data): + # Process output_data as needed + return processed_output_data +``` + +``` javascript JavaScript +coming soon! +``` + + + + +```python Python +# While defining the toolset, you can define the metadata, schema, pre, and post processors +composio_toolset = ComposioToolSet( + metadata={ + App.FILETOOL: { + "app": "filetool", + }, + Action.GREPTILE_CODE_QUERY: { + "sessionId": "....", + }, + Action.LINEAR_CREATE_LINEAR_ISSUE: { + "project_id": "...", + }, + }, + processors={ + "schema": { + App.GITHUB: tool_schema_processor, + Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER: action_schema_processor, + }, + "pre": { + App.GITHUB: tool_preprocessor, + Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER: action_preprocessor, + }, + "post": { + App.GITHUB: tool_postprocessor, + Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER: action_postprocessor, + }, + }, +) + +tools = composio_toolset.get_tools(apps=[App.GITHUB]) +``` +``` javascript JavaScript +coming soon! +``` + + + + + + Ensure that your schema processing, preprocessing, and postprocessing functions are efficient and don't introduce significant latency. + diff --git a/docs/patterns/tools/use-tools/filter-actions.mdx b/docs/patterns/tools/use-tools/filter-actions.mdx deleted file mode 100644 index b4fd517145..0000000000 --- a/docs/patterns/tools/use-tools/filter-actions.mdx +++ /dev/null @@ -1,86 +0,0 @@ ---- -title: "Filtering Actions" -sidebarTitle: "Filter Actions" -icon: "filter" -description: "This documentation will guide you through the process of filtering actions based on different criteria." ---- - -Filtering actions is crucial for optimizing AI agent performance by narrowing down the action set to the most relevant ones. - -### Filtering Actions by Tags -Filter the Actions in an App based on tags. -For example, you can: -- Filter all user-related Actions using the "users" tag -- Retrieve metadata-related Actions using the "meta" tag - - -```python Python -from composio_langchain import ComposioToolSet, Action, App - -tools = tool_set.get_tools(apps=[App.GITHUB]) - -# Filter by tags -tag = "users" - -action_enums = toolset.find_actions_by_tags( - App.GITHUB, - tags=[tag], -) - -tools = tool_set.get_tools(actions=action_enums) -``` - -```javascript Javascript -import { OpenAIToolSet } from "composio-core"; - -const composio_toolset = new OpenAIToolSet(); - -// Filter by tags -const tag = "meta"; - -const actions = await composio_toolset.getTools({ - apps: ["github"], - tags: [tag], -}); - -console.log(actions); -``` - -```bash CLI -composio actions --app 'github' --tag 'code' -``` - - -### Filtering Actions by Use Case -Find relevant actions for your use case by describing your use case in natural language. - -```Python Python -from composio import ComposioToolSet, App, action - -toolset = ComposioToolSet() - -# Specify the use case -use_case="Star a repo on github" - -action_enums=toolset.find_actions_by_use_case(App.GITHUB, use_case=use_case) -tools = toolset.get_tools(actions=action_enums) -``` - -```Javascript Javascript -import { LangchainToolSet } from "composio-core"; - -const toolset = new LangchainToolSet(); - -// Specify the use case -const useCase = "Star a repo on github"; - -const actionsList = await toolset.client.actions.list({ - useCase: useCase, - apps: "github", -}); -``` - -```bash CLI -composio actions --use-case 'star a repo on github' --app 'github' -``` - diff --git a/docs/patterns/tools/use-tools/get-action-inputs.mdx b/docs/patterns/tools/use-tools/get-action-inputs.mdx index ebd4d3c435..0871781333 100644 --- a/docs/patterns/tools/use-tools/get-action-inputs.mdx +++ b/docs/patterns/tools/use-tools/get-action-inputs.mdx @@ -1,26 +1,19 @@ --- -title: "๐Ÿ› ๏ธ How can I get the input parameters for an Action?" -sidebarTitle: "Get Action Inputs" +title: "๐Ÿ› ๏ธ How can I get the schema for an Action?" +sidebarTitle: "Get Action Schema" icon: "text-size" -description: "Get the input parameters for an Action" +description: "Guide to get the schema for an Action" --- ### When will I need to provide input parameters? When executing actions without agents, you'll need to provide the input parameters. There are two ways to obtain these parameters: -1. Through the [API Section](/api-reference/actions/get-action) of our documentation -2. Programmatically using our SDK +1. Programmatically using our SDK +2. Using the [API Section](/api-reference/actions/get-action) of our documentation -### Using the [API Section](/api-reference/actions/get-action) from the Documentation - - -1. Navigate to the [API Section](/api-reference/actions/get-action) of our documentation -2. Click on **Get Action** under the **Actions** category -3. Enter your Composio API key and the Action ID -4. The **parameters** attribute in the response contains the required parameters for executing the action - -### Using the SDK + + ```python Python from composio import ComposioToolSet, Action @@ -61,4 +54,16 @@ console.log(JSON.stringify(schema[0].parameters.properties, null, 2)); "type": "string" } } -``` \ No newline at end of file +``` + + + + + +1. Navigate to the [API Section](/api-reference/actions/get-action) of our documentation +2. Click on **Get Action** under the **Actions** category +3. Enter your Composio API key and the Action ID +4. The **parameters** attribute in the response contains the required parameters for executing the action + + + \ No newline at end of file diff --git a/docs/patterns/tools/use-tools/processing-actions.mdx b/docs/patterns/tools/use-tools/processing-actions.mdx index 387af0d30f..56130bdffe 100644 --- a/docs/patterns/tools/use-tools/processing-actions.mdx +++ b/docs/patterns/tools/use-tools/processing-actions.mdx @@ -1,21 +1,17 @@ --- -title: "๐Ÿ› ๏ธ Enhancing Action Inputs, Outputs & Schemas" -sidebarTitle: "Processing Actions" +title: "๐Ÿ› ๏ธ How to modify Actions?" +sidebarTitle: "Modify Actions" icon: "wand-magic-sparkles" -description: "Master the art of preprocessing, postprocessing, and schema processing for optimal results." +description: "Learn how to modify Actions & Tools to refine inputs, outputs, and schemas for optimal results." --- -## Metadata - -The `metadata` in the `ComposioToolSet` configuration is used to add metadata for different Apps/Tools and Actions. e.g., session IDs, agent IDs or API keys. This allows for flexible and dynamic configuration of tools and actions within the Composio framework, ensuring that critical data are reliably passed. - ## Refining Action Inputs, Outputs & Schemas In many scenarios, the raw inputs, outputs, or schemas of actions may benefit from additional processing. This refinement step can significantly improve the quality and usability of your data. Here are three key use cases: -- **Preprocessing**: Generate or modify inputs dynamically at runtime, handling scenarios that may be challenging for the LLM to produce directly. -- **Postprocessing**: Streamline large action responses by filtering or formatting the data before it reaches the Language Model (LLM). +- **Preprocessing**: Generate or modify inputs dynamically at runtime, handling scenarios that may be challenging for the LLM to produce directly. e.g., passing project_id & team_id to the `LINEAR_CREATE_LINEAR_ISSUE` action. +- **Postprocessing**: Streamline large action responses by filtering or formatting the data before it reaches the Language Model (LLM). e.g., extracting just the messageText from the response of `GMAIL_FETCH_EMAILS` action. - **Schema Processing**: Modify the request schema to include additional fields or alter existing ones. Composio empowers you with the ability to define **custom functions** as preprocessors, postprocessors, or schema processors. @@ -25,81 +21,264 @@ These can be applied at two levels: 1. **Tool-level**: Affects all actions within a specific tool. 2. **Action-level**: Tailored processing for individual actions. -Here's how you can implement these processors: + + + - + ```python Python -def tool_schema_processor(schema): - # Modify schema as needed - return modified_schema - -def tool_preprocessor(input_data): - # Modify input_data as needed - return modified_input_data +from langchain.agents import create_openai_functions_agent, AgentExecutor +from langchain import hub +from langchain_openai import ChatOpenAI +from composio_langchain import ComposioToolSet, Action, App +``` +```javascript JavaScript +Coming Soon +``` + + + + +```python Python +prompt = hub.pull("hwchase17/openai-functions-agent") -def tool_postprocessor(output_data): - # Process output_data as needed - return processed_output_data +llm = ChatOpenAI() +composio_toolset = ComposioToolSet() +``` +```javascript JavaScript +Coming Soon +``` + + + +This function will be used to modify the input data for the `LINEAR_CREATE_LINEAR_ISSUE` action. here we have added the `project_id` and the `team_id` to the input data, by doing this can can avoid specifying these values in the prompt and be sure that agent uses the correct values. The technical term for this is **Action-level Preprocessor**. + +```python Python +def linear_pre_processor(input_data: dict) -> dict: + input_data['project_id'] = 'e708162b-9b1a-4901-ab93-0f0149f9d805' + input_data['team_id'] = '249ee4cc-7bbb-4ff1-adbe-d3ef2f3df94e' + return input_data +``` +```javascript JavaScript +Coming Soon +``` + + + +When getting tools using the `get_tools()` method, we need to pass the `processors` parameter to specify any preprocessing functions. In this example, we're setting up an Action-level preprocessor by mapping the `LINEAR_CREATE_LINEAR_ISSUE` action to our `request_pre_processor` function defined above. This tells Composio to run the input data through our preprocessor function before executing this specific action. -def action_schema_processor(schema): - # Modify schema as needed - return modified_schema + +```python Python +tools = composio_toolset.get_tools( + processors={ + "pre": { + Action.LINEAR_CREATE_LINEAR_ISSUE: linear_pre_processor, + }, + }, + actions=[Action.LINEAR_CREATE_LINEAR_ISSUE] +) +``` +```javascript JavaScript +Coming Soon +``` + + + + +```python Python +task = "Create a Linear Issue with to update the frontend" -def action_preprocessor(input_data): - # Modify input_data as needed - return modified_input_data +agent = create_openai_functions_agent(llm, tools, prompt) +agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True) -def action_postprocessor(output_data): - # Process output_data as needed - return processed_output_data +agent_executor.invoke({"input": task}) ``` +```javascript JavaScript +Coming Soon +``` + + + + + + + + +```python Python +from langchain.agents import create_openai_functions_agent, AgentExecutor +from langchain import hub +from langchain_openai import ChatOpenAI +from composio_langchain import ComposioToolSet, Action, App +``` +```javascript JavaScript +Coming Soon +``` + + + + +```python Python +prompt = hub.pull("hwchase17/openai-functions-agent") -``` javascript JavaScript -coming soon! +llm = ChatOpenAI() +composio_toolset = ComposioToolSet() +``` +```javascript JavaScript +Coming Soon ``` - + +This function will be used to modify the output data for the `GMAIL_FETCH_EMAILS` action. here we are extracting just the messageText from the response, doing this we fine tuning the response and keeping the LLMs context clear & concise. The technical term for this is **Action-level Postprocessor**. ```python Python -# While defining the toolset, you can define the metadata, schema, pre, and post processors -composio_toolset = ComposioToolSet( - metadata={ - App.FILETOOL: { - "app": "filetool", - }, - Action.GREPTILE_CODE_QUERY: { - "sessionId": "....", - }, - Action.LINEAR_CREATE_LINEAR_ISSUE: { - "project_id": "...", +def gmail_post_processor(output_data: dict) -> dict: + message = output_data.get('data', {}).get('response_data', {}).get('messages', [{}])[0].get('messageText', '') + return message +``` +```javascript JavaScript +Coming Soon +``` + + + +When getting tools using the `get_tools()` method, we need to pass the `processors` parameter to specify any postprocessing functions. In this example, we're setting up an Action-level postprocessor by mapping the `GMAIL_FETCH_EMAILS` action to our `gmail_post_processor` function defined above. This tells Composio to run the output data through our postprocessor function before returning the response to the LLM. + + +```python Python +tools = composio_toolset.get_tools( + processors={ + "post": { + Action.GMAIL_FETCH_EMAILS: gmail_post_processor, }, }, + actions=[Action.GMAIL_FETCH_EMAILS] +) +``` +```javascript JavaScript +Coming Soon +``` + + + + +```python Python +task = "List the last email in the inbox (max_results=1)" + +agent = create_openai_functions_agent(llm, tools, prompt) +agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True) + +agent_executor.invoke({"input": task}) +``` +```javascript JavaScript +Coming Soon +``` + + + + + + + + +```python Python +from langchain.agents import create_openai_functions_agent, AgentExecutor +from langchain import hub +from langchain_openai import ChatOpenAI +from composio_langchain import ComposioToolSet, Action, App +``` +```javascript JavaScript +Coming Soon +``` + + + + +```python Python +prompt = hub.pull("hwchase17/openai-functions-agent") + +llm = ChatOpenAI() +composio_toolset = ComposioToolSet() +``` +```javascript JavaScript +Coming Soon +``` + + + +This function will be used to modify the schema. The technical term for this is **Action-level Schema Processor**. + +```python Python +def modify_schema(schema: dict) -> dict: + # modify the schema here + return modified_schema +``` +```javascript JavaScript +Coming Soon +``` + + + +When getting tools using the `get_tools()` method, we need to pass the `processors` parameter to specify any schema processing functions. In this example, we're demoing how to modify the schema for the any action by mapping the `modify_schema` function defined above. This tells Composio to run the schema through our schema processor function before calling the action. + + +```python Python +tools = composio_toolset.get_tools( processors={ "schema": { - App.GITHUB: tool_schema_processor, - Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER: action_schema_processor, + Action.: modify_schema, }, + }, + actions=[Action.] +) +``` +```javascript JavaScript +Coming Soon +``` + + + + +```python Python +task = "prompt" + +agent = create_openai_functions_agent(llm, tools, prompt) +agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True) + +agent_executor.invoke({"input": task}) +``` +```javascript JavaScript +Coming Soon +``` + + + + + + +### How to use processors at Tool-level / App-level? + +```python Python +tools = composio_toolset.get_tools( + processors={ "pre": { - App.GITHUB: tool_preprocessor, - Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER: action_preprocessor, + App.: processor_function, }, "post": { - App.GITHUB: tool_postprocessor, - Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER: action_postprocessor, + App.: processor_function, + }, + "schema": { + App.: processor_function, }, }, + apps=[App.] ) - -tools = composio_toolset.get_tools(apps=[App.GITHUB]) ``` -``` javascript JavaScript -coming soon! +```javascript JavaScript +Coming Soon ``` - - Ensure that your schema processing, preprocessing, and postprocessing functions are efficient and don't introduce significant latency. diff --git a/docs/patterns/tools/use-tools/processing-old.mdx b/docs/patterns/tools/use-tools/processing-old.mdx new file mode 100644 index 0000000000..deaa99e422 --- /dev/null +++ b/docs/patterns/tools/use-tools/processing-old.mdx @@ -0,0 +1,106 @@ +--- +title: "๐Ÿ› ๏ธ How to modify Actions?" +sidebarTitle: "Modify Actions" +icon: "wand-magic-sparkles" +description: "Learn how to modify actions to refine inputs, outputs, and schemas for optimal results." +--- + +## Metadata + +The `metadata` in the `ComposioToolSet` configuration is used to add metadata for different Apps/Tools and Actions. e.g., session IDs, agent IDs or API keys. This allows for flexible and dynamic configuration of tools and actions within the Composio framework, ensuring that critical data are reliably passed. + + +## Refining Action Inputs, Outputs & Schemas + +In many scenarios, the raw inputs, outputs, or schemas of actions may benefit from additional processing. This refinement step can significantly improve the quality and usability of your data. Here are three key use cases: + +- **Preprocessing**: Generate or modify inputs dynamically at runtime, handling scenarios that may be challenging for the LLM to produce directly. +- **Postprocessing**: Streamline large action responses by filtering or formatting the data before it reaches the Language Model (LLM). +- **Schema Processing**: Modify the request schema to include additional fields or alter existing ones. + +Composio empowers you with the ability to define **custom functions** as preprocessors, postprocessors, or schema processors. + +These can be applied at two levels: + +1. **Tool-level**: Affects all actions within a specific tool. +2. **Action-level**: Tailored processing for individual actions. + +Here's how you can implement these processors: + + + +```python Python +def tool_schema_processor(schema): + # Modify schema as needed + return modified_schema + +def tool_preprocessor(input_data): + # Modify input_data as needed + return modified_input_data + +def tool_postprocessor(output_data): + # Process output_data as needed + return processed_output_data + +def action_schema_processor(schema): + # Modify schema as needed + return modified_schema + +def action_preprocessor(input_data): + # Modify input_data as needed + return modified_input_data + +def action_postprocessor(output_data): + # Process output_data as needed + return processed_output_data +``` + +``` javascript JavaScript +coming soon! +``` + + + + +```python Python +# While defining the toolset, you can define the metadata, schema, pre, and post processors +composio_toolset = ComposioToolSet( + metadata={ + App.FILETOOL: { + "app": "filetool", + }, + Action.GREPTILE_CODE_QUERY: { + "sessionId": "....", + }, + Action.LINEAR_CREATE_LINEAR_ISSUE: { + "project_id": "...", + }, + }, + processors={ + "schema": { + App.GITHUB: tool_schema_processor, + Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER: action_schema_processor, + }, + "pre": { + App.GITHUB: tool_preprocessor, + Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER: action_preprocessor, + }, + "post": { + App.GITHUB: tool_postprocessor, + Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER: action_postprocessor, + }, + }, +) + +tools = composio_toolset.get_tools(apps=[App.GITHUB]) +``` +``` javascript JavaScript +coming soon! +``` + + + + + + Ensure that your schema processing, preprocessing, and postprocessing functions are efficient and don't introduce significant latency. + diff --git a/docs/patterns/tools/use-tools/use-specific-actions.mdx b/docs/patterns/tools/use-tools/use-specific-actions.mdx index 9b6e8ea44e..c6af346e61 100644 --- a/docs/patterns/tools/use-tools/use-specific-actions.mdx +++ b/docs/patterns/tools/use-tools/use-specific-actions.mdx @@ -1,14 +1,16 @@ --- -title: "Use Specific Actions" +title: "How can I get and use specific actions from a Tool?" sidebarTitle: "Use Specific Actions" icon: "pickaxe" -description: "You can select specific Actions from a given App by specifying action IDs." +description: "Each Tool (like GitHub, Slack, etc.) comes with many Actions. You can explore all available Tools & Actions [here](https://app.composio.dev/apps). Each Action has an associated action ID which you can use to call the action." --- -Specifying specific Actions is crucial for optimizing AI agent performance by narrowing down the action set to the most relevant ones. + + Filtering actions is crucial for optimizing AI agent performance. Providing too many actions can overwhelm the LLM's decision-making process, making it harder to choose the most appropriate action. It's best to narrow down the action set to only the most relevant ones for your specific use case. + -### Specifying Actions by ID -`GITHUB_CREATE_AN_ISSUE` and `GITHUB_COMMIT_EVENT` are action IDs for the Github Tool/App. +### Specifying Actions +`GITHUB_CREATE_AN_ISSUE` and `GITHUB_COMMIT_EVENT` are action IDs for actions in the Github Tool ```python Python from composio import ComposioToolSet, App, action @@ -27,4 +29,87 @@ const toolset = new LangchainToolSet(); // can pass multiple actions const tools = await toolset.getTools({actions: ['github_issues_create','github_commit_event']}); ``` - \ No newline at end of file + + +### Filtering Actions +Actions can be filtered by tags or use case. + + +Filter the Actions in an App based on tags. +For example, you can: +- Filter all user-related Actions using the "users" tag +- Retrieve metadata-related Actions using the "meta" tag + + +```python Python +from composio_langchain import ComposioToolSet, Action, App + +tools = tool_set.get_tools(apps=[App.GITHUB]) + +# Filter by tags +tag = "users" + +action_enums = toolset.find_actions_by_tags( + App.GITHUB, + tags=[tag], +) + +tools = tool_set.get_tools(actions=action_enums) +``` + +```javascript Javascript +import { OpenAIToolSet } from "composio-core"; + +const composio_toolset = new OpenAIToolSet(); + +// Filter by tags +const tag = "meta"; + +const actions = await composio_toolset.getTools({ + apps: ["github"], + tags: [tag], +}); + +console.log(actions); +``` + +```bash CLI +composio actions --app 'github' --tag 'code' +``` + + + +Find relevant actions for your use case by describing your use case in natural language. + +```Python Python +from composio import ComposioToolSet, App, action + +toolset = ComposioToolSet() + +# Specify the use case +use_case="Star a repo on github" + +action_enums=toolset.find_actions_by_use_case(App.GITHUB, use_case=use_case) +tools = toolset.get_tools(actions=action_enums) +``` + +```Javascript Javascript +import { LangchainToolSet } from "composio-core"; + +const toolset = new LangchainToolSet(); + +// Specify the use case +const useCase = "Star a repo on github"; + +const actionsList = await toolset.client.actions.list({ + useCase: useCase, + apps: "github", +}); +``` + +```bash CLI +composio actions --use-case 'star a repo on github' --app 'github' +``` + + + From 7b689305862690a28b7270dd46ae3baca76e6de8 Mon Sep 17 00:00:00 2001 From: abhishekpatil4 Date: Fri, 22 Nov 2024 00:49:52 +0530 Subject: [PATCH 20/25] feat: add configure tools page --- docs/mint.json | 1 + .../tools/use-tools/configure-tools.mdx | 136 ++++++++---------- 2 files changed, 63 insertions(+), 74 deletions(-) diff --git a/docs/mint.json b/docs/mint.json index 6cc581badf..786dd91af2 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -142,6 +142,7 @@ "patterns/tools/use-tools/use-specific-actions", "patterns/tools/use-tools/get-action-inputs", "patterns/tools/use-tools/processing-actions", + "patterns/tools/use-tools/configure-tools", "patterns/tools/use-tools/action-guide-without-agents" ] }, diff --git a/docs/patterns/tools/use-tools/configure-tools.mdx b/docs/patterns/tools/use-tools/configure-tools.mdx index ee335e7929..c1972b1de1 100644 --- a/docs/patterns/tools/use-tools/configure-tools.mdx +++ b/docs/patterns/tools/use-tools/configure-tools.mdx @@ -1,106 +1,94 @@ --- title: "๐Ÿ› ๏ธ Configure Tools" sidebarTitle: "Configure Tools" -icon: "wand-magic-sparkles" +icon: "gear" description: "Learn how to configure tools" --- ## Metadata -The `metadata` in the `ComposioToolSet` configuration is used to add metadata for different Apps/Tools and Actions. e.g., session IDs, agent IDs or API keys. This allows for flexible and dynamic configuration of tools and actions within the Composio framework, ensuring that critical data are reliably passed. +The `metadata` in the `ComposioToolSet` configuration is used to add metadata for different Apps/Tools and Actions. This metadata can include essential configuration like API keys, session IDs, or agent IDs. This allows for flexible and dynamic configuration of tools and actions within the Composio framework. +Composio empowers you with the ability to add metadata at two levels: -## Refining Action Inputs, Outputs & Schemas +1. **Tool/App-level**: Applies to all actions within a specific tool/app +2. **Action-level**: Specific configuration for individual actions -In many scenarios, the raw inputs, outputs, or schemas of actions may benefit from additional processing. This refinement step can significantly improve the quality and usability of your data. Here are three key use cases: - -- **Preprocessing**: Generate or modify inputs dynamically at runtime, handling scenarios that may be challenging for the LLM to produce directly. -- **Postprocessing**: Streamline large action responses by filtering or formatting the data before it reaches the Language Model (LLM). -- **Schema Processing**: Modify the request schema to include additional fields or alter existing ones. - -Composio empowers you with the ability to define **custom functions** as preprocessors, postprocessors, or schema processors. - -These can be applied at two levels: - -1. **Tool-level**: Affects all actions within a specific tool. -2. **Action-level**: Tailored processing for individual actions. - -Here's how you can implement these processors: - + ```python Python -def tool_schema_processor(schema): - # Modify schema as needed - return modified_schema - -def tool_preprocessor(input_data): - # Modify input_data as needed - return modified_input_data - -def tool_postprocessor(output_data): - # Process output_data as needed - return processed_output_data - -def action_schema_processor(schema): - # Modify schema as needed - return modified_schema - -def action_preprocessor(input_data): - # Modify input_data as needed - return modified_input_data - -def action_postprocessor(output_data): - # Process output_data as needed - return processed_output_data +from langchain.agents import create_openai_functions_agent, AgentExecutor +from langchain import hub +from langchain_openai import ChatOpenAI +from composio_langchain import ComposioToolSet, Action, App ``` - -``` javascript JavaScript -coming soon! +```javascript JavaScript +Coming Soon ``` - + +During the initialization of the `ComposioToolSet` client, we can add metadata for different Actions/Tools. In this example, we're adding an OpenAI API key for the `IMAGE_ANALYSER_ANALYSE` action: ```python Python -# While defining the toolset, you can define the metadata, schema, pre, and post processors +prompt = hub.pull("hwchase17/openai-functions-agent") + +llm = ChatOpenAI() composio_toolset = ComposioToolSet( metadata={ - App.FILETOOL: { - "app": "filetool", - }, - Action.GREPTILE_CODE_QUERY: { - "sessionId": "....", - }, - Action.LINEAR_CREATE_LINEAR_ISSUE: { - "project_id": "...", - }, - }, - processors={ - "schema": { - App.GITHUB: tool_schema_processor, - Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER: action_schema_processor, - }, - "pre": { - App.GITHUB: tool_preprocessor, - Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER: action_preprocessor, - }, - "post": { - App.GITHUB: tool_postprocessor, - Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER: action_postprocessor, + Action.IMAGE_ANALYSER_ANALYSE: { + "OPENAI_API_KEY": "", }, }, ) +``` +```javascript JavaScript +Coming Soon +``` + + + + +```python Python +tools = composio_toolset.get_tools( + actions=[Action.IMAGE_ANALYSER_ANALYSE], +) +``` +```javascript JavaScript +Coming Soon +``` + + + + +```python Python +task = "Describe the image. Path: /Users/soham/desktop/image.png" + +agent = create_openai_functions_agent(llm, tools, prompt) +agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True) -tools = composio_toolset.get_tools(apps=[App.GITHUB]) +agent_executor.invoke({"input": task}) ``` -``` javascript JavaScript -coming soon! +```javascript JavaScript +Coming Soon ``` - - Ensure that your schema processing, preprocessing, and postprocessing functions are efficient and don't introduce significant latency. - +### How to add metadata at Tool-level / App-level? + +```python Python +toolset = ComposioToolSet( + metadata={ + App.: { + "attribute": "value", + } + } +) +``` +```javascript JavaScript +Coming Soon +``` + From 98ab37b653d4f3b2122e42817595900493480dee Mon Sep 17 00:00:00 2001 From: abhishekpatil4 Date: Fri, 22 Nov 2024 13:12:30 +0530 Subject: [PATCH 21/25] fix: schema processing --- .../tools/use-tools/processing-actions.mdx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/patterns/tools/use-tools/processing-actions.mdx b/docs/patterns/tools/use-tools/processing-actions.mdx index 56130bdffe..f984b589e7 100644 --- a/docs/patterns/tools/use-tools/processing-actions.mdx +++ b/docs/patterns/tools/use-tools/processing-actions.mdx @@ -207,12 +207,12 @@ Coming Soon -This function will be used to modify the schema. The technical term for this is **Action-level Schema Processor**. +This function will be used to modify the schema for the `TWITTER_CREATION_OF_A_POST` action. Here we're adding the character limit specification to the `text` field's `description`. The technical term for this is **Action-level Schema Processor**. ```python Python -def modify_schema(schema: dict) -> dict: - # modify the schema here - return modified_schema +def twitter_schema_processor(schema: dict) -> dict: + schema['text']['description'] = 'The content of the Tweet. Maximum 280 characters' + return schema ``` ```javascript JavaScript Coming Soon @@ -220,17 +220,17 @@ Coming Soon -When getting tools using the `get_tools()` method, we need to pass the `processors` parameter to specify any schema processing functions. In this example, we're demoing how to modify the schema for the any action by mapping the `modify_schema` function defined above. This tells Composio to run the schema through our schema processor function before calling the action. +When getting tools using the `get_tools()` method, we need to pass the `processors` parameter to specify any schema processing functions. In this example, we're setting up a Action-level schema processor by mapping the `TWITTER_CREATION_OF_A_POST` action to our `twitter_schema_processor` function defined above. This tells Composio to run the schema through our schema processor function before executing this specific action. ```python Python tools = composio_toolset.get_tools( processors={ "schema": { - Action.: modify_schema, + Action.TWITTER_CREATION_OF_A_POST: twitter_schema_processor, }, }, - actions=[Action.] + actions=[Action.TWITTER_CREATION_OF_A_POST] ) ``` ```javascript JavaScript @@ -241,7 +241,7 @@ Coming Soon ```python Python -task = "prompt" +task = "Create a post on Twitter with title: Hey, I used composio to create this post!" agent = create_openai_functions_agent(llm, tools, prompt) agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True) From 5ed9f68bb6da388245d2cbf738912a04a17792ad Mon Sep 17 00:00:00 2001 From: abhishekpatil4 Date: Fri, 22 Nov 2024 16:11:22 +0530 Subject: [PATCH 22/25] feat: update modify actions page --- .../tools/use-tools/configure-tools.mdx | 1 + .../tools/use-tools/processing-actions.mdx | 200 ++++-------------- 2 files changed, 40 insertions(+), 161 deletions(-) diff --git a/docs/patterns/tools/use-tools/configure-tools.mdx b/docs/patterns/tools/use-tools/configure-tools.mdx index c1972b1de1..c458937525 100644 --- a/docs/patterns/tools/use-tools/configure-tools.mdx +++ b/docs/patterns/tools/use-tools/configure-tools.mdx @@ -78,6 +78,7 @@ Coming Soon ### How to add metadata at Tool-level / App-level? +Above we saw how to add metadata at the Action-level, now we will see how to add them at the Tool-level/App-level. ```python Python toolset = ComposioToolSet( diff --git a/docs/patterns/tools/use-tools/processing-actions.mdx b/docs/patterns/tools/use-tools/processing-actions.mdx index f984b589e7..5da1e08a04 100644 --- a/docs/patterns/tools/use-tools/processing-actions.mdx +++ b/docs/patterns/tools/use-tools/processing-actions.mdx @@ -2,19 +2,19 @@ title: "๐Ÿ› ๏ธ How to modify Actions?" sidebarTitle: "Modify Actions" icon: "wand-magic-sparkles" -description: "Learn how to modify Actions & Tools to refine inputs, outputs, and schemas for optimal results." +description: "Learn how to modify Tools & Actions to refine schemas, inputs, and outputs for optimal results." --- -## Refining Action Inputs, Outputs & Schemas +## Refining Tool Schemas, Inputs, & Outputs -In many scenarios, the raw inputs, outputs, or schemas of actions may benefit from additional processing. This refinement step can significantly improve the quality and usability of your data. Here are three key use cases: +In many scenarios, the schemas, inputs, or outputs of tools may benefit from additional processing. This refinement step can significantly improve the quality and usability of your data. Here are three key use cases: -- **Preprocessing**: Generate or modify inputs dynamically at runtime, handling scenarios that may be challenging for the LLM to produce directly. e.g., passing project_id & team_id to the `LINEAR_CREATE_LINEAR_ISSUE` action. -- **Postprocessing**: Streamline large action responses by filtering or formatting the data before it reaches the Language Model (LLM). e.g., extracting just the messageText from the response of `GMAIL_FETCH_EMAILS` action. -- **Schema Processing**: Modify the request schema to include additional fields or alter existing ones. +- **Modifying Schema**: Adjust how your tool describes its requirements. For example, if you're automatically providing certain values in input(like project_id), you can mark these fields as "not required" in the schema so the LLM knows it doesn't need to ask for them. +- **Modifying Inputs**: Add values as inputs to avoid specifying them in the prompt. e.g., passing `project_id` & `team_id` to the `LINEAR_CREATE_LINEAR_ISSUE` action. +- **Modifying Outputs**: Modify outputs to get the desired data. e.g., extracting `execution_id` & `issue_id` from the response of `LINEAR_CREATE_LINEAR_ISSUE` action. Doing this can help keep the LLM context clean. -Composio empowers you with the ability to define **custom functions** as preprocessors, postprocessors, or schema processors. +Composio empowers you with the ability to define **custom functions** as schema modifiers, input modifiers, or output modifiers. These can be applied at two levels: @@ -22,8 +22,6 @@ These can be applied at two levels: 2. **Action-level**: Tailored processing for individual actions. - - @@ -51,78 +49,27 @@ Coming Soon ``` - -This function will be used to modify the input data for the `LINEAR_CREATE_LINEAR_ISSUE` action. here we have added the `project_id` and the `team_id` to the input data, by doing this can can avoid specifying these values in the prompt and be sure that agent uses the correct values. The technical term for this is **Action-level Preprocessor**. - -```python Python -def linear_pre_processor(input_data: dict) -> dict: - input_data['project_id'] = 'e708162b-9b1a-4901-ab93-0f0149f9d805' - input_data['team_id'] = '249ee4cc-7bbb-4ff1-adbe-d3ef2f3df94e' - return input_data -``` -```javascript JavaScript -Coming Soon -``` - - - -When getting tools using the `get_tools()` method, we need to pass the `processors` parameter to specify any preprocessing functions. In this example, we're setting up an Action-level preprocessor by mapping the `LINEAR_CREATE_LINEAR_ISSUE` action to our `request_pre_processor` function defined above. This tells Composio to run the input data through our preprocessor function before executing this specific action. - - -```python Python -tools = composio_toolset.get_tools( - processors={ - "pre": { - Action.LINEAR_CREATE_LINEAR_ISSUE: linear_pre_processor, - }, - }, - actions=[Action.LINEAR_CREATE_LINEAR_ISSUE] -) -``` -```javascript JavaScript -Coming Soon -``` - - - - -```python Python -task = "Create a Linear Issue with to update the frontend" - -agent = create_openai_functions_agent(llm, tools, prompt) -agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True) - -agent_executor.invoke({"input": task}) -``` -```javascript JavaScript -Coming Soon -``` - - - - - - - + +This function will be used to modify the schema of the `LINEAR_CREATE_LINEAR_ISSUE` action, here we are modifying the descritpion for the parameters `project_id` & `team_id` to not required, later in the porgram we will pass these values as inputs to the action. The technical term for this is **Action-level Schema Processing**. ```python Python -from langchain.agents import create_openai_functions_agent, AgentExecutor -from langchain import hub -from langchain_openai import ChatOpenAI -from composio_langchain import ComposioToolSet, Action, App +def linear_schema_processor(schema: dict) -> dict: + schema['project_id']['description'] = schema['project_id']['description'].replace('is required', 'not required') + schema['team_id']['description'] = schema['team_id']['description'].replace('is required', 'not required') + return schema ``` ```javascript JavaScript Coming Soon ``` - - + +This function will be used to modify the input data for the `LINEAR_CREATE_LINEAR_ISSUE` action. here we have added the values for `project_id` and `team_id` parameters to the input data, by doing this can can avoid specifying these values in the prompt and be sure that agent uses the correct values. The technical term for this is **Action-level Pre-Processing**. ```python Python -prompt = hub.pull("hwchase17/openai-functions-agent") - -llm = ChatOpenAI() -composio_toolset = ComposioToolSet() +def linear_pre_processor(input_data: dict) -> dict: + input_data['project_id'] = 'e708162b-9b1a-4901-ab93-0f0149f9d805' + input_data['team_id'] = '249ee4cc-7bbb-4ff1-adbe-d3ef2f3df94e' + return input_data ``` ```javascript JavaScript Coming Soon @@ -130,107 +77,39 @@ Coming Soon -This function will be used to modify the output data for the `GMAIL_FETCH_EMAILS` action. here we are extracting just the messageText from the response, doing this we fine tuning the response and keeping the LLMs context clear & concise. The technical term for this is **Action-level Postprocessor**. - -```python Python -def gmail_post_processor(output_data: dict) -> dict: - message = output_data.get('data', {}).get('response_data', {}).get('messages', [{}])[0].get('messageText', '') - return message -``` -```javascript JavaScript -Coming Soon -``` - - - -When getting tools using the `get_tools()` method, we need to pass the `processors` parameter to specify any postprocessing functions. In this example, we're setting up an Action-level postprocessor by mapping the `GMAIL_FETCH_EMAILS` action to our `gmail_post_processor` function defined above. This tells Composio to run the output data through our postprocessor function before returning the response to the LLM. - +This function will be used to modify the output data for the `LINEAR_CREATE_LINEAR_ISSUE` action. here we are modifing the output to just return the action execution status `successfull` & the `issue_id`, by doing this can keep the LLM context clean. The technical term for this is **Action-level Post-Processing**. ```python Python -tools = composio_toolset.get_tools( - processors={ - "post": { - Action.GMAIL_FETCH_EMAILS: gmail_post_processor, - }, - }, - actions=[Action.GMAIL_FETCH_EMAILS] -) +def linear_post_processor(output_data: dict) -> dict: + output_data = { + 'success': output_data['successfull'], + 'issue_id': output_data['data']['id'] + } + return output_data ``` ```javascript JavaScript Coming Soon ``` - - -```python Python -task = "List the last email in the inbox (max_results=1)" - -agent = create_openai_functions_agent(llm, tools, prompt) -agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True) - -agent_executor.invoke({"input": task}) -``` -```javascript JavaScript -Coming Soon -``` - - - - - - - - -```python Python -from langchain.agents import create_openai_functions_agent, AgentExecutor -from langchain import hub -from langchain_openai import ChatOpenAI -from composio_langchain import ComposioToolSet, Action, App -``` -```javascript JavaScript -Coming Soon -``` - - - - -```python Python -prompt = hub.pull("hwchase17/openai-functions-agent") - -llm = ChatOpenAI() -composio_toolset = ComposioToolSet() -``` -```javascript JavaScript -Coming Soon -``` - - - -This function will be used to modify the schema for the `TWITTER_CREATION_OF_A_POST` action. Here we're adding the character limit specification to the `text` field's `description`. The technical term for this is **Action-level Schema Processor**. - -```python Python -def twitter_schema_processor(schema: dict) -> dict: - schema['text']['description'] = 'The content of the Tweet. Maximum 280 characters' - return schema -``` -```javascript JavaScript -Coming Soon -``` - - - -When getting tools using the `get_tools()` method, we need to pass the `processors` parameter to specify any schema processing functions. In this example, we're setting up a Action-level schema processor by mapping the `TWITTER_CREATION_OF_A_POST` action to our `twitter_schema_processor` function defined above. This tells Composio to run the schema through our schema processor function before executing this specific action. + +When getting tools using the `get_tools()` method, we need to pass the `processors` parameter to specify the schema, pre-processing, and post-processing functions. In this example, we're setting up an Action-level preprocessor by mapping the `LINEAR_CREATE_LINEAR_ISSUE` action to our `linear_schema_processor`, `linear_pre_processor` and `linear_post_processor` functions defined above respectively in schema, pre, and post processors. ```python Python tools = composio_toolset.get_tools( processors={ "schema": { - Action.TWITTER_CREATION_OF_A_POST: twitter_schema_processor, + Action.LINEAR_CREATE_LINEAR_ISSUE: linear_schema_processor, + }, + "pre": { + Action.LINEAR_CREATE_LINEAR_ISSUE: linear_pre_processor, }, + "post": { + Action.LINEAR_CREATE_LINEAR_ISSUE: linear_post_processor, + } }, - actions=[Action.TWITTER_CREATION_OF_A_POST] + actions=[Action.LINEAR_CREATE_LINEAR_ISSUE] ) ``` ```javascript JavaScript @@ -241,7 +120,7 @@ Coming Soon ```python Python -task = "Create a post on Twitter with title: Hey, I used composio to create this post!" +task = "Create a Linear Issue with to update the frontend" agent = create_openai_functions_agent(llm, tools, prompt) agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True) @@ -254,10 +133,9 @@ Coming Soon - - -### How to use processors at Tool-level / App-level? +### How to use processors at Tool-level/App-level? +Above we saw how to use processors at the Action-level, now we will see how to use them at the Tool-level/App-level. ```python Python tools = composio_toolset.get_tools( From ec4b6c00a426a67f4070c38c3781bdd3b4f7fe0e Mon Sep 17 00:00:00 2001 From: abhishekpatil4 Date: Fri, 22 Nov 2024 18:30:06 +0530 Subject: [PATCH 23/25] update --- docs/mint.json | 2 +- .../custom-action-for-existing-tool.mdx | 16 +-- .../custom-action-for-new-tool.mdx | 10 +- docs/patterns/tools/custom-integration.mdx | 10 +- .../tools/use-tools/configure-tools.mdx | 24 ++-- .../tools/use-tools/processing-actions.mdx | 12 +- .../tools/use-tools/processing-old.mdx | 106 ------------------ 7 files changed, 37 insertions(+), 143 deletions(-) delete mode 100644 docs/patterns/tools/use-tools/processing-old.mdx diff --git a/docs/mint.json b/docs/mint.json index 786dd91af2..879af9e2d5 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -12,7 +12,7 @@ "colors": { "primary": "#343434", "light": "#fff", - "dark": "#9a4dff", + "dark": "#343434", "ultraLight": "#9a4dff", "ultraDark": "#9a4dff", "background": { diff --git a/docs/patterns/tools/build-tools/custom-action-for-existing-tool.mdx b/docs/patterns/tools/build-tools/custom-action-for-existing-tool.mdx index 0be597a977..dcd5e6b8ff 100644 --- a/docs/patterns/tools/build-tools/custom-action-for-existing-tool.mdx +++ b/docs/patterns/tools/build-tools/custom-action-for-existing-tool.mdx @@ -1,15 +1,15 @@ --- -title: "Build an Action for existing Tool" -sidebarTitle: "Build an Action for existing Tool" +title: "Build Tools with Auth" +sidebarTitle: "Build Tools with Auth" icon: "toolbox" -description: "Extend the functionality of existing tools by creating a custom action which utilises the existing authentication. (e.g., fetch emails from Gmail)" +description: "Create custom actions that leverage existing tool authentication to extend functionality." --- -Custom Actions are flexible building blocks that let you create any functionality you need - from simple calculations to complex integrations. They work seamlessly with Composio's authentication system for existing tools, or can run independently for custom logic. +Custom Actions are powerful building blocks that enable you to create custom functionality while leveraging existing tool authentication. They can handle everything from simple data processing to complex third-party integrations, either using pre-configured tool authentication or running independently. -## Creating a Custom Action for an Existing Tool +## Creating a Custom Action with Authentication @@ -30,10 +30,10 @@ const toolset = new OpenAIToolSet({}) -Below is an example of creating `my_custom_action` a custom action for the `gmail` tool. The action is designed to fetch emails from a Gmail account for the last 24 hours using the existing authentication provided by Composio. - +Below is an example of creating a custom action called `my_custom_action` that integrates with the `gmail` tool. This action demonstrates how to fetch emails from the last 24 hours while utilizing Composio's built-in Gmail authentication. -As `gmail` toolname is already registered in Composio, `auth` dictionary will be automatically provided! + +Since `gmail` is a registered tool in Composio, the `auth` credentials are automatically injected into your custom action! ```python Python diff --git a/docs/patterns/tools/build-tools/custom-action-for-new-tool.mdx b/docs/patterns/tools/build-tools/custom-action-for-new-tool.mdx index 85fb58ff72..8965605264 100644 --- a/docs/patterns/tools/build-tools/custom-action-for-new-tool.mdx +++ b/docs/patterns/tools/build-tools/custom-action-for-new-tool.mdx @@ -1,15 +1,15 @@ --- -title: "Build an Action for new Tool" -sidebarTitle: "Build an Action for new Tool" +title: "Build Tools without Auth" +sidebarTitle: "Build Tools without Auth" icon: "plus" -description: "Create standalone custom Tool and Action for any functionality you need (e.g., data processing, calculations, or integrations with other services)" +description: "Create standalone custom tools and actions for any functionality you need (e.g., data processing, calculations, or integrations with other services)" --- -Custom Actions are flexible building blocks that let you create any functionality you need - from simple calculations to complex integrations. They work seamlessly with Composio's authentication system for existing tools, or can run independently for custom logic. +Custom Actions are powerful building blocks that enable you to create custom functionality while running independently. They can handle everything from simple data processing to complex third-party integrations. -## Creating a Custom Action for a New Tool +## Creating a Custom Tool without Authentication diff --git a/docs/patterns/tools/custom-integration.mdx b/docs/patterns/tools/custom-integration.mdx index 9b753668e0..e6f53dd8cf 100644 --- a/docs/patterns/tools/custom-integration.mdx +++ b/docs/patterns/tools/custom-integration.mdx @@ -1,13 +1,13 @@ --- -title: "๐Ÿ”ง How to build Apps?" -sidebarTitle: "Build Apps" +title: "๐Ÿ”ง How to add your own App?" +sidebarTitle: "Add Your Own App" icon: "puzzle-piece" -description: "Learn how to create custom tools with external Apps using OpenAPI Spec" +description: "Learn how to add your own App to Composio" --- -Creating custom tools on Composio is straightforward and can be done via an [OpenAPI Spec](https://swagger.io/specification/). +Creating your own App on Composio is straightforward and can be done via an [OpenAPI Spec](https://swagger.io/specification/). -Here's a tutorial showing how to create a Custom Tool for Notion +Here's a tutorial showing how to add Notion as an App on Composio