Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 04:45 UTC
| 1 | import type { ReferenceDocument } from '../reference-schema'; |
| 2 | |
| 3 | export const powerUserExamplesReference: ReferenceDocument = { |
| 4 | slug: 'power-user-examples', |
| 5 | title: 'Power-User Examples', |
| 6 | intro: [ |
| 7 | 'Load this file when the user needs more than one top-level command or wants to script workflows with `composio run`.', |
| 8 | ], |
| 9 | sections: [ |
| 10 | { |
| 11 | title: 'Use `run` To Chain Tool Calls', |
| 12 | body: [ |
| 13 | 'Fetch from multiple connected tools in one script:', |
| 14 | 'If the user does not need script logic and just wants a few independent calls, prefer top-level parallel execute instead:', |
| 15 | ], |
| 16 | commands: [ |
| 17 | { |
| 18 | code: `composio run ' |
| 19 | const me = await execute("GITHUB_GET_THE_AUTHENTICATED_USER"); |
| 20 | const emails = await execute("GMAIL_FETCH_EMAILS", { |
| 21 | max_results: 2, |
| 22 | }); |
| 23 | |
| 24 | console.log({ |
| 25 | login: me.data.login, |
| 26 | emailCount: Array.isArray(emails.data?.messages) ? emails.data.messages.length : null, |
| 27 | }); |
| 28 | '`, |
| 29 | }, |
| 30 | { |
| 31 | code: `composio execute --parallel \\ |
| 32 | GMAIL_FETCH_EMAILS -d '{ max_results: 2 }' \\ |
| 33 | GITHUB_GET_THE_AUTHENTICATED_USER -d '{}'`, |
| 34 | }, |
| 35 | ], |
| 36 | }, |
| 37 | { |
| 38 | title: 'Use `Promise.all` To Fan Out', |
| 39 | body: ['Fetch from multiple services at once:'], |
| 40 | commands: [ |
| 41 | { |
| 42 | code: `composio run ' |
| 43 | const [me, emails] = await Promise.all([ |
| 44 | execute("GITHUB_GET_THE_AUTHENTICATED_USER"), |
| 45 | execute("GMAIL_FETCH_EMAILS", { max_results: 5 }), |
| 46 | ]); |
| 47 | |
| 48 | console.log({ |
| 49 | login: me.data.login, |
| 50 | emailCount: emails.data.messages?.length ?? null, |
| 51 | }); |
| 52 | '`, |
| 53 | }, |
| 54 | ], |
| 55 | }, |
| 56 | { |
| 57 | title: 'Use `search()` Before `execute()` Inside A Script', |
| 58 | body: [ |
| 59 | 'Discover a candidate slug, then execute it:', |
| 60 | 'Batch related discovery work with multiple queries when it keeps the workflow simpler:', |
| 61 | ], |
| 62 | commands: [ |
| 63 | { |
| 64 | code: `composio run ' |
| 65 | const results = await search("get the authenticated github user", { |
| 66 | toolkits: "github", |
| 67 | limit: 1, |
| 68 | }); |
| 69 | |
| 70 | const slug = results.results?.[0]?.primary_tool_slugs?.[0]; |
| 71 | if (!slug) throw new Error("No candidate tool found."); |
| 72 | |
| 73 | const output = await execute(slug); |
| 74 | |
| 75 | console.log(output.data.login); |
| 76 | '`, |
| 77 | }, |
| 78 | { |
| 79 | code: 'composio search "send an email" "create a github issue" --toolkits gmail,github', |
| 80 | }, |
| 81 | ], |
| 82 | }, |
| 83 | { |
| 84 | title: 'Use `proxy()` For Raw API Access', |
| 85 | body: [ |
| 86 | '`proxy(toolkit)` returns a fetch-compatible function bound to the connected account. Name it like `fetch` if that keeps the script clearer. It returns a real `Response`, so call `.json()` or `.text()`.', |
| 87 | ], |
| 88 | commands: [ |
| 89 | { |
| 90 | code: `composio run ' |
| 91 | const fetch = await proxy("github"); |
| 92 | const profile = await (await fetch("https://api.github.com/user")).json(); |
| 93 | console.log(profile); |
| 94 | '`, |
| 95 | }, |
| 96 | ], |
| 97 | }, |
| 98 | { |
| 99 | title: 'Mix `execute()` And `proxy()`', |
| 100 | body: [ |
| 101 | 'Use dedicated tools where they exist, then drop down to raw API calls for the missing step:', |
| 102 | ], |
| 103 | commands: [ |
| 104 | { |
| 105 | code: `composio run ' |
| 106 | const me = await execute("GITHUB_GET_THE_AUTHENTICATED_USER"); |
| 107 | |
| 108 | const fetch = await proxy("github"); |
| 109 | const repos = await (await fetch("https://api.github.com/user/repos?per_page=3")).json(); |
| 110 | |
| 111 | console.log({ |
| 112 | login: me.data.login, |
| 113 | repoCount: Array.isArray(repos) ? repos.length : null, |
| 114 | }); |
| 115 | '`, |
| 116 | }, |
| 117 | ], |
| 118 | }, |
| 119 | { |
| 120 | title: 'Use `run` Flags Intentionally', |
| 121 | body: [ |
| 122 | '- Use `--dry-run` to preview every `execute()` call in the script.', |
| 123 | '- Use `--debug` to see helper steps while the script runs.', |
| 124 | 'Example:', |
| 125 | ], |
| 126 | commands: [ |
| 127 | { |
| 128 | code: `composio run --dry-run --debug 'await execute("GITHUB_CREATE_AN_ISSUE", { owner: "acme", repo: "app", title: "Bug report", body: "Steps to reproduce..." })'`, |
| 129 | }, |
| 130 | ], |
| 131 | }, |
| 132 | ], |
| 133 | }; |