Using In-chat authentication

In-chat authentication lets your agent prompt users to connect accounts during chat. When a tool requires authentication, the agent returns a Connect Link URL. The user authenticates, confirms in chat, and the agent retries.

How it works

  1. Agent searches for tools via the COMPOSIO_SEARCH_TOOLS meta-tool
  2. The COMPOSIO_MANAGE_CONNECTIONS meta-tool checks connection status, returns Connect Link URL if needed
  3. User authenticates, confirms in chat, agent continues

Configuration

By just creating a session with default configs, you are enabling in-chat auth. The manage_connections parameter defaults to True, which includes the COMPOSIO_MANAGE_CONNECTIONS meta-tool automatically:

1session = composio.create(user_id="user_123")

Custom callback URL

Redirect users back to your chat page after they complete authentication:

1session = composio.create(
2 user_id="user_123",
3 manage_connections={
4 "callback_url": "https://yourapp.com/chat"
5 },
6)

Examples

1from dotenv import load_dotenv
2from composio import Composio
3from agents import Agent, Runner, SQLiteSession
4from composio_openai_agents import OpenAIAgentsProvider
5
6load_dotenv()
7
8# Initialize Composio with OpenAI Agents provider (API key from env var COMPOSIO_API_KEY)
9composio = Composio(provider=OpenAIAgentsProvider())
10
11# Unique identifier of the user
12user_id = "user_123"
13
14# Create a session and get native tools for the user
15session = composio.create(user_id=user_id)
16tools = session.tools()
17
18# Configure OpenAI agent with Composio tools
19agent = Agent(
20 name="Personal Assistant",
21 instructions="You are a helpful personal assistant. Use Composio tools to take action.",
22 model="gpt-5.2",
23 tools=tools,
24)
25
26# Memory for multi-turn conversation
27memory = SQLiteSession("conversation")
28
29print("""
30What task would you like me to help you with?
31I can use tools like Gmail, GitHub, Linear, Notion, and more.
32(Type 'exit' to exit)
33Example tasks:
34 • 'Summarize my emails from today'
35 • 'List all open issues on the composio github repository'
36""")
37
38while True:
39 user_input = input("You: ").strip()
40 if user_input.lower() == "exit":
41 break
42
43 print("Assistant: ", end="", flush=True)
44 try:
45 result = Runner.run_sync(starting_agent=agent, input=user_input, session=memory)
46 print(f"{result.final_output}\n")
47 except Exception as e:
48 print(f"\n[Error]: {e}")

What this looks like when you run the code:

Assistant: What would you like me to do today? Type 'exit' to end the conversation.
> Star the composio repo on GitHub
Assistant: I need you to connect your GitHub account first.
Please click here to authorize: https://connect.composio.dev/link/ln_abc123
> Done
Assistant: Done! I've starred ComposioHQ/composio.

To manage authentication outside of chat, see Manually authenticating users.