Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
py 62 lines 1.56 KB
Raw
1 import os
2
3 import dotenv
4 from autogen import AssistantAgent, LLMConfig, UserProxyAgent
5 from composio_autogen import AutogenProvider
6
7 from composio import Composio
8
9 # Load environment variables from .env
10 dotenv.load_dotenv()
11
12
13 def is_termination_msg(content: dict) -> bool:
14 """Check if a message contains termination message."""
15 return "TERMINATE" in (content.get("content", "") or "")
16
17
18 def main():
19 # Initialize tools.
20 chatbot = AssistantAgent(
21 "chatbot",
22 system_message="Reply TERMINATE when the task is done or when user's content is empty",
23 llm_config=LLMConfig(
24 {
25 "api_type": "openai",
26 "model": "gpt-5",
27 "api_key": os.environ["OPENAI_API_KEY"],
28 }
29 ),
30 )
31
32 # Create a user proxy agent
33 user_proxy = UserProxyAgent(
34 "user_proxy",
35 is_termination_msg=is_termination_msg,
36 human_input_mode="NEVER",
37 code_execution_config={"use_docker": False},
38 )
39
40 # Get composio tools
41 composio = Composio(provider=AutogenProvider())
42 tools = composio.tools.get(user_id="default", toolkits=["GITHUB"])
43
44 # Register the preferred Applications, with right executor.
45 composio.provider.register_tools(
46 caller=chatbot,
47 executor=user_proxy,
48 tools=tools,
49 )
50
51 # Define task.
52 task = "Star a repo composiohq/composio on GitHub"
53
54 # Execute task.
55 response = user_proxy.initiate_chat(chatbot, message=task)
56
57 # Print response
58 print(response.chat_history)
59
60
61 if __name__ == "__main__":
62 main()