Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
kaavee315 committed Jan 14, 2025
1 parent 93f5d03 commit 6194d73
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
23 changes: 10 additions & 13 deletions python/plugins/autogen/autogen_demo_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@
Autogen demo using get_tools() approach.
"""

import asyncio
import os

import dotenv
from autogen import AssistantAgent, UserProxyAgent
from autogen_agentchat.agents import AssistantAgent
from autogen_core import CancellationToken
from autogen_ext.models.openai import OpenAIChatCompletionClient

from composio_autogen import App, ComposioToolSet


def main():
async def main():
# Initialize toolset and get tools
composio_toolset = ComposioToolSet()
tools = composio_toolset.get_tools(apps=[App.GITHUB])

model_client = OpenAIChatCompletionClient(
model="gpt-4o",
model="gpt-4",
api_key=os.environ["OPENAI_API_KEY"],
)
# Create assistant agent with tools
assistant = AssistantAgent(
Expand All @@ -27,22 +30,16 @@ def main():
"Use the provided tools to interact with GitHub."
),
model_client=model_client,
tools=tools,
)

# Create user proxy agent
user_proxy = UserProxyAgent(
name="user_proxy",
human_input_mode="NEVER",
code_execution_config={"work_dir": "coding"},
tools=list(tools),
)

# Define task and initiate chat
task = "Star the repository composiohq/composio on GitHub"
user_proxy.initiate_chat(assistant, message=task)
result = await assistant.run(task=task, cancellation_token=CancellationToken())
print(result)


if __name__ == "__main__":
# Load environment variables from .env
dotenv.load_dotenv()
main()
asyncio.run(main())
32 changes: 19 additions & 13 deletions python/plugins/autogen/composio_autogen/toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,12 @@ def execute_action(**kwargs: t.Any) -> t.Dict:
params = get_signature_format_from_schema_params(
schema_params=schema["parameters"],
)
setattr(function, '__signature__', Signature(parameters=params))
setattr(function, '__annotations__', {
p.name: p.annotation for p in params
} | {'return': t.Dict[str, t.Any]})
setattr(function, "__signature__", Signature(parameters=params))
setattr(
function,
"__annotations__",
{p.name: p.annotation for p in params} | {"return": t.Dict[str, t.Any]},
)
function.__doc__ = (
description if description else f"Action {name} from {appName}"
)
Expand All @@ -166,11 +168,11 @@ def _wrap_tool(
) -> FunctionTool:
"""
Wraps a composio action as an Autogen FunctionTool.
Args:
schema: The action schema to wrap
entity_id: Optional entity ID for executing function calls
Returns:
FunctionTool: Wrapped function as an Autogen FunctionTool
"""
Expand All @@ -193,13 +195,17 @@ def execute_action(**kwargs: t.Any) -> t.Dict:
name=self._process_function_name_for_registration(input_string=name),
closure=execute_action.__closure__,
)

# Set signature and annotations
params = get_signature_format_from_schema_params(schema_params=schema["parameters"])
setattr(function, '__signature__', Signature(parameters=params))
setattr(function, '__annotations__', {
p.name: p.annotation for p in params
} | {'return': t.Dict[str, t.Any]})
params = get_signature_format_from_schema_params(
schema_params=schema["parameters"]
)
setattr(function, "__signature__", Signature(parameters=params))
setattr(
function,
"__annotations__",
{p.name: p.annotation for p in params} | {"return": t.Dict[str, t.Any]},
)
function.__doc__ = description

return FunctionTool(
Expand All @@ -223,7 +229,7 @@ def get_tools(
Args:
actions: List of actions to wrap
apps: List of apps to wrap
apps: List of apps to wrap
tags: Filter apps by given tags
entity_id: Entity ID for function wrapper
processors: Optional dict of processors to merge
Expand Down

0 comments on commit 6194d73

Please sign in to comment.