-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from ComposioHQ/sawra/local_tool_tutorial
Local tools tutorial+ example added
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |