Skip to content

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

feat: add llamaindex provider

angrybayblade871086dcc175
diff --git a/python/providers/llamaindex/README.md b/python/providers/llamaindex/README.md
new file mode 100644
index 000000000..9a9811cb8
--- /dev/null
+++ b/python/providers/llamaindex/README.md
@@ -0,0 +1,4 @@
+## Using Composio With LLamaIndex
+
+Integrate Composio with LLamaIndex Agentic workflows & enable them to interact seamlessly
+with external apps, enhancing their functionality and reach.
diff --git a/python/providers/llamaindex/composio_llamaindex/__init__.py b/python/providers/llamaindex/composio_llamaindex/__init__.py
new file mode 100644
index 000000000..961669006
--- /dev/null
+++ b/python/providers/llamaindex/composio_llamaindex/__init__.py
@@ -0,0 +1,3 @@
+from .provider import LlamaIndexProvider
+
+__all__ = ("LlamaIndexProvider",)
diff --git a/python/providers/llamaindex/composio_llamaindex/provider.py b/python/providers/llamaindex/composio_llamaindex/provider.py
new file mode 100644
index 000000000..97113a386
--- /dev/null
+++ b/python/providers/llamaindex/composio_llamaindex/provider.py
@@ -0,0 +1,62 @@
+"""ComposioLangChain class definition"""
+
+import types
+import typing as t
+from inspect import Signature
+
+from llama_index.core.tools import FunctionTool
+
+from composio.core.provider import AgenticProvider, AgenticProviderExecuteFn
+from composio.types import Tool
+from composio.utils.shared import get_signature_format_from_schema_params
+
+
+class LlamaIndexProvider(
+ AgenticProvider[FunctionTool, t.List[FunctionTool]],
+ name="llamaindex",
+):
+ """
+ Composio toolset for LlamaIndex framework.
+ """
+
+ def wrap_tool(
+ self,
+ tool: Tool,
+ execute_tool: AgenticProviderExecuteFn,
+ ) -> FunctionTool:
+ """
+ Wrap a tool into a LlamaIndex FunctionTool object.
+ """
+
+ def function(**kwargs: t.Any) -> t.Dict:
+ """Wrapper function for composio action."""
+ return execute_tool(slug=tool.slug, arguments=kwargs)
+
+ action_func = types.FunctionType(
+ function.__code__,
+ globals=globals(),
+ name=tool.slug,
+ closure=function.__closure__,
+ )
+ action_func.__signature__ = Signature( # type: ignore
+ parameters=get_signature_format_from_schema_params(
+ schema_params=tool.input_parameters,
+ skip_default=self.skip_default,
+ )
+ )
+ action_func.__doc__ = tool.description
+ return FunctionTool.from_defaults(
+ action_func,
+ name=tool.slug,
+ description=tool.description,
+ )
+
+ def wrap_tools(
+ self,
+ tools: t.Sequence[Tool],
+ execute_tool: AgenticProviderExecuteFn,
+ ) -> t.List[FunctionTool]:
+ """
+ Wrap tools into LlamaIndex FunctionTool objects.
+ """
+ return [self.wrap_tool(tool, execute_tool) for tool in tools]
diff --git a/python/providers/llamaindex/composio_llamaindex/py.typed b/python/providers/llamaindex/composio_llamaindex/py.typed
new file mode 100644
index 000000000..e69de29bb
diff --git a/python/providers/llamaindex/llamaindex_demo.py b/python/providers/llamaindex/llamaindex_demo.py
new file mode 100644
index 000000000..f55566d0f
--- /dev/null
+++ b/python/providers/llamaindex/llamaindex_demo.py
@@ -0,0 +1,38 @@
+import asyncio
+
+import dotenv
+from composio_llamaindex import LlamaIndexProvider
+from llama_index.core.agent.workflow import FunctionAgent
+from llama_index.llms.openai import OpenAI
+
+from composio import Composio
+
+# Load environment variables from .env
+dotenv.load_dotenv()
+
+# Setup client
+llm = OpenAI(model="gpt-4-turbo")
+composio = Composio(provider=LlamaIndexProvider())
+
+# Get All the tools
+tools = composio.tools.get(
+ user_id="default",
+ tools=["GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER"],
+)
+
+workflow = FunctionAgent(
+ tools=tools,
+ llm=llm,
+ system_prompt="You are an agent that perform github actions.",
+)
+
+
+async def main():
+ result = await workflow.run(
+ user_msg="Hello! I would like to star a repo composiohq/composio on GitHub"
+ )
+ print(result)
+
+
+if __name__ == "__main__":
+ asyncio.run(main())
diff --git a/python/providers/llamaindex/pyproject.toml b/python/providers/llamaindex/pyproject.toml
new file mode 100644
index 000000000..ec870357b
--- /dev/null
+++ b/python/providers/llamaindex/pyproject.toml
@@ -0,0 +1,20 @@
+[project]
+name = "composio-llamaindex"
+version = "0.8.9"
+description = "Use Composio to get array of tools with LlamaIndex Agent Workflows."
+readme = "README.md"
+requires-python = ">=3.9,<4"
+authors = [
+ { name = "Composio", email = "[email protected]" }
+]
+classifiers = [
+ "Programming Language :: Python :: 3",
+ "License :: OSI Approved :: Apache Software License",
+ "Operating System :: OS Independent",
+]
+dependencies = [
+ "llama_index",
+]
+
+[project.urls]
+Homepage = "https://github.com/ComposioHQ/composio"
diff --git a/python/providers/llamaindex/setup.py b/python/providers/llamaindex/setup.py
new file mode 100644
index 000000000..df413fdf1
--- /dev/null
+++ b/python/providers/llamaindex/setup.py
@@ -0,0 +1,26 @@
+"""
+Setup configuration for Composio LangGraph plugin
+"""
+
+from pathlib import Path
+
+from setuptools import setup
+
+setup(
+ name="composio_llamaindex",
+ version="0.8.9",
+ author="composio",
+ author_email="[email protected]",
+ description="Use Composio to get array of tools with LlamaIndex Agent Workflows",
+ long_description=(Path(__file__).parent / "README.md").read_text(encoding="utf-8"),
+ long_description_content_type="text/markdown",
+ url="https://github.com/ComposioHQ/composio",
+ classifiers=[
+ "Programming Language :: Python :: 3",
+ "License :: OSI Approved :: Apache Software License",
+ "Operating System :: OS Independent",
+ ],
+ python_requires=">=3.9,<4",
+ install_requires=["llama-index"],
+ include_package_data=True,
+)