Skip to content

Commit

Permalink
Merge pull request #107 from ComposioHQ/sawra/local_tool_tutorial
Browse files Browse the repository at this point in the history
Local tools tutorial+ example added
  • Loading branch information
utkarsh-dixit authored Jun 7, 2024
2 parents 712504d + 2d240bd commit f6edb63
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions composio/local_tools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Composio is your one-stop solution for all kind of LLM tools and functionalities. And a very important step on that front is the ability of adding your own custom tools. Once we add a tool(or Action).


This page contains necessary details for using Local Tools: [Local Tools Page](https://docs.composio.dev/sdk/python/local_tools)
48 changes: 48 additions & 0 deletions examples/local_tools/autogen_math.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os

import dotenv
from autogen import AssistantAgent, UserProxyAgent
from composio_autogen import App, ComposioToolSet


# Load environment variables from .env
dotenv.load_dotenv()


# Initialize tools.
chatbot = AssistantAgent(
"chatbot",
system_message="Reply TERMINATE when the task is done or when user's content is empty",
llm_config={
"config_list": [
{"model": "gpt-4", "api_key": os.environ["OPENAI_API_KEY"]},
]
},
)
composio_toolset = ComposioToolSet()


def is_termination_msg(content: dict) -> bool:
"""Check if a message contains termination message."""
return "TERMINATE" in (content.get("content", "") or "")


# Create a user proxy agent
user_proxy = UserProxyAgent(
"user_proxy",
is_termination_msg=is_termination_msg,
human_input_mode="NEVER",
code_execution_config={"use_docker": False},
)

# Register the preferred Applications, with right executor.
composio_toolset.register_tools(tools=[App.MATHEMATICAL], caller=chatbot, executor=user_proxy)

# Define task.
task = "What is 230 multiplied by 52 and added with 233 divided by 91?"

# Execute task.
response = user_proxy.initiate_chat(chatbot, message=task)

# Print response
print(response.chat_history)

0 comments on commit f6edb63

Please sign in to comment.