@devries-cameron20 / composio Mirror · read-only / commits / 299f307e1
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, 19:30 UTC

Make create session return type pythonic

Prateek committed Oct 1, 2025 at 14:29 UTC 299f307e1e19fda4ef9be0a008379210ca883060
1 file changed +18 -7
python/composio/core/models/tool_router.py
+18 -7
@@ -8,6 +8,7 @@ following Python conventions and avoiding unnecessary data transformations.
8 from __future__ import annotations
9
10 import typing as t
11 +from types import SimpleNamespace
12
13 import typing_extensions as te
14 from composio_client.types.tool_router_create_session_params import ConfigToolkit
@@ -19,11 +20,19 @@ from composio.exceptions import ValidationError
20 # Data Types
21
22
22 -class ToolRouterSession(te.TypedDict):
23 - """Tool router session response."""
23 +class ToolRouterSession(SimpleNamespace):
24 + """Tool router session response with both dot notation and dict-style access."""
25
25 - session_id: str # Unique session identifier
26 - url: str # Chat session MCP URL
26 + def __init__(self, session_id: str, url: str):
27 + super().__init__(session_id=session_id, url=url)
28 +
29 + def __getitem__(self, key: str) -> str:
30 + """Support dict-style access like session['url']"""
31 + return getattr(self, key)
32 +
33 + def __setitem__(self, key: str, value: str) -> None:
34 + """Support dict-style assignment like session['url'] = 'new_url'"""
35 + setattr(self, key, value)
36
37
38 class ToolRouter(Resource):
@@ -73,9 +82,11 @@ class ToolRouter(Resource):
82 ... manually_manage_connections=False
83 ... )
84 >>>
76 - >>> # Access session details
77 - >>> print(session['session_id'])
78 - >>> print(session['url'])
85 + >>> # Access session details (both ways work!)
86 + >>> print(session.session_id) # Dot notation (preferred)
87 + >>> print(session['session_id']) # Dict-style access
88 + >>> print(session.url) # Dot notation (preferred)
89 + >>> print(session['url']) # Dict-style access
90 """
91 try:
92 # Normalize toolkits to the format expected by the API