@devries-cameron20 / composio Mirror · read-only / commits / 81067dad8
Fork 0

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 22, 02:00 UTC

style(python): clean up example file spacing

Single blank lines between definitions, noqa for E302/E303 since this is an example file not a library module. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Dhawal Upadhyay committed Mar 23, 2026 at 17:58 UTC 81067dad81be9dbb05f45ff2acf7dfd521b0ded7
1 file changed +3 -33
python/examples/custom_tools_agent_test.py
+3 -33
@@ -8,6 +8,7 @@ extension (Gmail proxy), and custom toolkit.
8 Usage:
9 COMPOSIO_API_KEY=... OPENAI_API_KEY=... python examples/custom_tools_agent_test.py
10 """
11 +# ruff: noqa: E302, E303
12
13 import asyncio
14 import base64
@@ -16,26 +17,21 @@ import sys
17
18 from agents import Agent, Runner
19 from pydantic import BaseModel, Field
19 -
20 from composio import Composio
21 from composio_openai_agents import OpenAIAgentsProvider
22
23 composio = Composio(provider=OpenAIAgentsProvider())
24
25 -
25 # ── 1. Standalone tool — slug/name/description inferred from function ──
26
28 -
27 class UserLookupInput(BaseModel):
28 user_id: str = Field(description="User ID (e.g. user-1)")
29
32 -
30 USERS = {
31 "user-1": {"name": "Alice Johnson", "email": "alice@acme.com", "role": "admin"},
32 "user-2": {"name": "Bob Smith", "email": "bob@acme.com", "role": "developer"},
33 }
34
38 -
35 @composio.experimental.tool()
36 def get_user(input: UserLookupInput, ctx):
37 """Look up an internal user by ID. Returns name, email, and role."""
@@ -43,21 +39,16 @@ def get_user(input: UserLookupInput, ctx):
39 if not user:
40 raise ValueError(f'User "{input.user_id}" not found')
41 return user
46 -
47 -
42 # slug = GET_USER (from function name)
43 # name = Get User (humanized)
44 # description = "Look up an internal user by ID..." (from docstring)
45
52 -
46 # ── 2. Standalone tool with overrides ──────────────────────────────────
47
55 -
48 class GreetInput(BaseModel):
49 name: str = Field(description="Name to greet")
50 style: str = Field(default="friendly", description="Greeting style")
51
60 -
52 @composio.experimental.tool(
53 slug="GREET_V2",
54 name="Greeting Generator",
@@ -71,22 +62,17 @@ def greet(input: GreetInput, ctx):
62 "casual": f"Yo {input.name}, what's up?",
63 }
64 return {"message": greetings.get(input.style, f"Hello {input.name}!")}
74 -
75 -
65 # slug = GREET_V2 (overridden, not GREET)
66 # name = Greeting Generator (overridden, not Greet)
67 # description = "Generate a personalized..." (overridden, not docstring)
68
80 -
69 # ── 3. Extension tool — inherits Gmail auth via ctx.proxy_execute() ────
70
83 -
71 class DraftInput(BaseModel):
72 to: str = Field(description="Recipient email address")
73 subject: str = Field(description="Email subject")
74 body: str = Field(description="Email body (plain text)")
75
89 -
76 @composio.experimental.tool(extends_toolkit="gmail")
77 def create_draft(input: DraftInput, ctx):
78 """Create a real Gmail draft. Appears in the user's drafts folder."""
@@ -106,37 +92,30 @@ def create_draft(input: DraftInput, ctx):
92 data = res["data"]
93 return {"draft_id": data["id"], "to": input.to, "subject": input.subject}
94
109 -
95 # ── 4. Custom toolkit — groups related tools under one namespace ───────
96
112 -
97 role_manager = composio.experimental.Toolkit(
98 slug="ROLE_MANAGER",
99 name="Role Manager",
100 description="Manage user roles in the system",
101 )
102
119 -
103 class SetRoleInput(BaseModel):
104 user_id: str = Field(description="User ID")
105 role: str = Field(description="New role (admin, developer, viewer)")
106
124 -
107 @role_manager.tool()
108 def set_role(input: SetRoleInput, ctx):
109 """Set a user's role. Returns confirmation."""
110 return {"user_id": input.user_id, "role": input.role, "updated": True}
111
130 -
112 @role_manager.tool(name="List All Roles")
113 def list_roles(input: UserLookupInput, ctx):
114 """List available roles for a user."""
115 return {"roles": ["admin", "developer", "viewer"], "current": "admin"}
116
136 -
117 # ── Agent ──────────────────────────────────────────────────────────────
118
139 -
119 async def run_test(prompt, test_name):
120 print(f"\n{'=' * 60}")
121 print(f"TEST: {test_name}")
@@ -152,7 +131,6 @@ async def run_test(prompt, test_name):
131 },
132 )
133 tools = session.tools()
155 -
134 agent = Agent(
135 name="Assistant",
136 instructions=(
@@ -172,7 +150,6 @@ async def run_test(prompt, test_name):
150 print(f"\nERROR: {e}")
151 return False
152
175 -
153 async def main():
154 tests = [
155 ("Look up user-2", "Standalone (inferred slug/name)"),
@@ -180,14 +157,8 @@ async def main():
157 ("Set user-1 role to developer", "Toolkit tool"),
158 ("Look up user-1 and set their role to viewer", "Mixed local tools"),
159 ("What is the weather in Tokyo?", "Remote (weathermap)"),
183 - (
184 - 'Draft an email to bob@acme.com with subject "Test" and body "Hello!"',
185 - "Gmail proxy (extends_toolkit)",
186 - ),
187 - (
188 - "Look up user-1, draft them an email saying hi, include weather in SF",
189 - "Mixed all paths",
190 - ),
160 + ('Draft an email to bob@acme.com with subject "Test" and body "Hello!"', "Gmail proxy"),
161 + ("Look up user-1, draft them an email saying hi, include weather in SF", "Mixed all"),
162 ]
163
164 results = []
@@ -202,7 +173,6 @@ async def main():
173 print(f" [{'PASS' if ok else 'FAIL'}] {name}")
174 print(f"\n{sum(1 for _, ok in results if ok)}/{len(results)} passed")
175
205 -
176 if __name__ == "__main__":
177 if not os.environ.get("OPENAI_API_KEY"):
178 print("Error: OPENAI_API_KEY env var required")