Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
utkarsh-dixit committed Apr 2, 2024
0 parents commit 9b06b7b
Show file tree
Hide file tree
Showing 36 changed files with 1,918 additions and 0 deletions.
97 changes: 97 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Build and Release

on:
push:
branches:
- master
tags:
- 'v*'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine build
pip install -r core/requirements.txt
pip install -r langchain/requirements.txt
pip install -r crew_ai/requirements.txt
- name: Extract version from tag
id: tag_version
run: |
echo "PACKAGE_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
echo $PACKAGE_VERSION
- name: Build core package and install locally
run: |
cd core
if [[ $GITHUB_REF == refs/tags/v* ]]; then
sed -i "s/version = '.*'/version = '${{ env.PACKAGE_VERSION }}'/" setup.py
echo "Updated version in setup.py (core)"
fi
python -m build
echo "Installing package locally"
pip install -e .
cd ..
- name: Publish package (Core)
if: startsWith(github.ref, 'refs/tags/v')
run: |
cd core && twine upload dist/* && cd ../
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}

- name: Build langchain package and install locally
run: |
cd langchain
pip install -e .
if [[ $GITHUB_REF == refs/tags/v* ]]; then
sed -i "s/version = '.*'/version = '${{ env.PACKAGE_VERSION }}'/" setup.py
sed -i "s/composio_core===.*/composio_core===${{ env.PACKAGE_VERSION }}\",/" pyproject.toml
sed -i "s/composio_core===.*/composio_core===${{ env.PACKAGE_VERSION }}/" requirements.txt
echo "Updated version in pyproject.toml and requirements.txt"
fi
python -m build
echo "Installing package locally"
cd ..
- name: Publish package (Langchain)
if: startsWith(github.ref, 'refs/tags/v')
run: |
cd langchain && twine upload dist/* && cd ../
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}

- name: Build crew package and install locally
run: |
cd crew_ai
echo "Installing package locally"
pip install -e .
if [[ $GITHUB_REF == refs/tags/v* ]]; then
sed -i "s/version = '.*'/version = '${{ env.PACKAGE_VERSION }}'/" setup.py
sed -i "s/composio_langchain===.*/composio_langchain===${{ env.PACKAGE_VERSION }}\",/" pyproject.toml
sed -i "s/composio_langchain===.*/composio_langchain===${{ env.PACKAGE_VERSION }}/" requirements.txt
echo "Updated version in pyproject.toml and requirements.txt"
fi
python -m build
cd ..
- name: Publish package (Crew AI)
if: startsWith(github.ref, 'refs/tags/v')
run: |
cd crew_ai && twine upload dist/* && cd ../
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
try.ipynb
*pycache*
user_data.json
.venv
venv*
**/dist
.DS_Store
*egg-info*
**/composio_autogen.egg-info
**/composio_llamaindex.egg-info
**/__pycache__
**/*.egg-info
5 changes: 5 additions & 0 deletions autogen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Composio <> Autogen
Use Composio to enhance your Autogen workflows with a suite of tools.

# Usage
Within your Autogen project:
2 changes: 2 additions & 0 deletions autogen/composio_autogen/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .autogen_toolspec import ComposioToolset
from composio import Action, App
169 changes: 169 additions & 0 deletions autogen/composio_autogen/autogen_toolspec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import types
import logging
from inspect import Parameter, Signature
from typing import Union, List, Annotated

import autogen
from composio import ComposioCore, App, Action, FrameworkEnum
from pydantic import create_model, Field
from autogen.agentchat.conversable_agent import ConversableAgent

logger = logging.getLogger(__name__)

schema_type_python_type_dict = {
'string': str,
'number': float,
'boolean': bool,
'integer': int
}

fallback_values = {
'string': "",
'number': 0.0,
'integer': 0.0,
'boolean': False,
'object': {},
'array': []
}

def pydantic_model_from_param_schema(param_schema):
fields = {}
param_title = param_schema['title'].replace(" ", "")
required_props = param_schema.get('required', [])
for prop_name, prop_info in param_schema['properties'].items():
prop_type = prop_info["type"]
prop_title = prop_info['title'].replace(" ", "")
prop_default = prop_info.get('default', fallback_values[prop_type])
if prop_type in schema_type_python_type_dict:
signature_prop_type = schema_type_python_type_dict[prop_type]
else:
signature_prop_type = pydantic_model_from_param_schema(prop_info)

if prop_name in required_props:
fields[prop_name] = (signature_prop_type,
Field(...,
title=prop_title,
description=prop_info.get('description',
prop_info.get('desc',
prop_title))
))
else:
fields[prop_name] = (signature_prop_type,
Field(title=prop_title,
default=prop_default
))
fieldModel = create_model(param_title, **fields)
return fieldModel




def get_signature_format_from_schema_params(
schema_params
):
parameters = []
required_params = schema_params.get('required', [])

for param_name, param_schema in schema_params['properties'].items():
param_type = param_schema['type']
param_title = param_schema['title'].replace(" ", "")

if param_type in schema_type_python_type_dict:
signature_param_type = schema_type_python_type_dict[param_type]
else:
signature_param_type = pydantic_model_from_param_schema(param_schema)

param_default = param_schema.get('default', fallback_values[param_type])
param_annotation = Annotated[signature_param_type, param_schema.get('description',
param_schema.get('desc',
param_title))]
param = Parameter(
name=param_name,
kind=Parameter.POSITIONAL_OR_KEYWORD,
annotation=param_annotation,
default=Parameter.empty if param_name in required_params else param_default
)
parameters.append(param)
return parameters


class ComposioToolset:
def __init__(self, caller = None, executor = None):
self.caller = caller
self.executor = executor
self.client = ComposioCore(framework=FrameworkEnum.AUTOGEN)


def register_tools(
self,
tools: Union[App, List[App]],
caller: ConversableAgent = None,
executor: ConversableAgent = None
):
if isinstance(tools, App):
tools = [tools]
assert caller or self.caller, "If caller hasn't been specified during initialization, has to be specified during registration"
assert executor or self.executor, "If executor hasn't been specified during initialization, has to be specified during registration"

action_schemas = self.client.sdk.get_list_of_actions(
apps=tools)

for schema in action_schemas:
self._register_schema_to_autogen(action_schema=schema,
caller = caller if caller else self.caller,
executor = executor if executor else self.executor)


def register_actions(
self,
actions: Union[Action, List[Action]],
caller: ConversableAgent = None,
executor: ConversableAgent = None
):
if isinstance(actions, Action):
actions = [actions]

assert caller or self.caller, "If caller hasn't been specified during initialization, has to be specified during registration"
assert executor or self.executor, "If executor hasn't been specified during initialization, has to be specified during registration"

action_schemas = self.client.sdk.get_list_of_actions(
actions=actions)

for schema in action_schemas:
self._register_schema_to_autogen(action_schema=schema,
caller = caller if caller else self.caller,
executor = executor if executor else self.executor)


def _register_schema_to_autogen(self,
action_schema,
caller: ConversableAgent,
executor: ConversableAgent):

name = action_schema["name"]
appName = action_schema["appName"]
description = action_schema["description"]

parameters = get_signature_format_from_schema_params(
action_schema["parameters"])
action_signature = Signature(parameters=parameters)

placeholder_function = lambda **kwargs: self.client.execute_action(
self.client.get_action_enum(name, appName),
kwargs)
action_func = types.FunctionType(
placeholder_function.__code__,
globals=globals(),
name=name,
closure=placeholder_function.__closure__
)
action_func.__signature__ = action_signature
action_func.__doc__ = description

autogen.agentchat.register_function(
action_func,
caller=caller,
executor=executor,
name=name,
description=description
)
11 changes: 11 additions & 0 deletions autogen/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[project]
dynamic = ["classifiers", "version", "readme", "authors", "requires-python", "description"]
dependencies = [
"composio_core===0.1.63",
"pyautogen===0.2.19"
]
name = "composio_autogen"

[build-system]
requires = [ "setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta"
2 changes: 2 additions & 0 deletions autogen/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
composio_core===0.1.24
pyautogen===0.2.19
31 changes: 31 additions & 0 deletions autogen/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from setuptools import setup
import os


def get_current_dir():
return os.path.dirname(os.path.realpath(__file__))


def resolve_paths(*paths):
return os.path.join(*paths)


readme_path = resolve_paths(get_current_dir(), "README.md")

setup(
name="composio_autogen",
version="0.1.63",
author="Sawradip",
author_email="[email protected]",
description="Use Composio to get an array of tools with your Autogen agent.",
long_description=open(readme_path).read(),
long_description_content_type="text/markdown",
url="https://github.com/SamparkAI/composio_sdk",
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
],
python_requires=">=3.7",
include_package_data=True,
)
2 changes: 2 additions & 0 deletions core/Manifest.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include requirements.txt
recursive-include lib *
3 changes: 3 additions & 0 deletions core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Composio Core Package

Core package to act as a bridge between composio platform and other services.
Loading

0 comments on commit 9b06b7b

Please sign in to comment.