Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ You can find some examples of how to use these adapters in the `adapters_example

- [LangGraph](https://github.com/oracle/agent-spec/tree/main/adapters_examples/langgraph)
- [AutoGen](https://github.com/oracle/agent-spec/tree/main/adapters_examples/autogen)
- [CrewAI](https://github.com/oracle/agent-spec/tree/main/adapters_examples/crewai)


## Positioning in the Agentic Ecosystem
Expand Down
85 changes: 85 additions & 0 deletions adapters_examples/crewai/agentspec_to_crewai.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Copyright © 2025 Oracle and/or its affiliates.
#
# This software is under the Apache License 2.0
# (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) or Universal Permissive License
# (UPL) 1.0 (LICENSE-UPL or https://oss.oracle.com/licenses/upl), at your option.

# mypy: ignore-errors

from pyagentspec.agent import Agent
from pyagentspec.llms import LlmGenerationConfig, VllmConfig
from pyagentspec.property import FloatProperty
from pyagentspec.tools import ClientTool, ServerTool

tools = [
ClientTool(
name="sum",
description="Sum two numbers",
inputs=[FloatProperty(title="a"), FloatProperty(title="b")],
outputs=[FloatProperty(title="result")],
),
ClientTool(
name="subtract",
description="Subtract two numbers",
inputs=[FloatProperty(title="a"), FloatProperty(title="b")],
outputs=[FloatProperty(title="result")],
),
ServerTool(
name="multiply",
description="Multiply two numbers",
inputs=[FloatProperty(title="a"), FloatProperty(title="b")],
outputs=[FloatProperty(title="result")],
),
ServerTool(
name="divide",
description="Divide two numbers",
inputs=[FloatProperty(title="a"), FloatProperty(title="b")],
outputs=[FloatProperty(title="result")],
),
]

agent = Agent(
name="calculator_agent",
description="An agent that provides assistance with tool use.",
llm_config=VllmConfig(
name="llama-maverick",
model_id="Llama-4-Maverick",
url="url.to.my.llama.model",
default_generation_parameters=LlmGenerationConfig(temperature=0.1),
),
system_prompt=(
"You are a helpful calculator agent.\n"
"Your duty is to compute the result of the given operation using tools, "
"and to output the result.\n"
"It's important that you reply with the result only.\n"
),
tools=tools,
)


from pyagentspec.adapters.crewai import AgentSpecLoader

importer = AgentSpecLoader(
tool_registry={
"divide": lambda a, b: a / b,
"multiply": lambda a, b: a * b,
}
)
calculator_agent = importer.load_component(agent)

from crewai import Crew, Task

task = Task(
description="{user_input}",
expected_output="A helpful, concise reply to the user.",
agent=calculator_agent,
)
crew = Crew(agents=[calculator_agent], tasks=[task])

print("=== Running Crew AI Calculator Agent ===")
while True:
user_input = input("USER >>> ")
if user_input.lower() in ["exit", "quit"]:
break
response = crew.kickoff(inputs={"user_input": user_input})
print("AGENT >>>", response)
104 changes: 104 additions & 0 deletions adapters_examples/crewai/crewai_to_agentspec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Copyright © 2025 Oracle and/or its affiliates.
#
# This software is under the Apache License 2.0
# (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) or Universal Permissive License
# (UPL) 1.0 (LICENSE-UPL or https://oss.oracle.com/licenses/upl), at your option.

# mypy: ignore-errors

from crewai import LLM, Agent
from crewai.tools.base_tool import Tool
from pydantic import BaseModel


class InputSchema(BaseModel):
a: float
b: float


def sum_(a: float, b: float) -> float:
"""Sum two numbers"""
return a + b


def subtract(a: float, b: float) -> float:
"""Subtract two numbers"""
return a - b


def multiply(a: float, b: float) -> float:
"""Multiply two numbers"""
return a * b


def divide(a: float, b: float) -> float:
"""Divide two numbers"""
return a / b


llm = LLM(
model="hosted_vllm/Llama-4-Maverick",
api_base="http://url.to.my.llama.model/v1",
max_tokens=512,
)

calculator_agent = Agent(
role="Calculator agent",
goal="Computes the mathematical operation prompted by the user",
backstory="You are a calculator with 20 years of experience",
llm=llm,
tools=[
Tool(
name="sum",
description="Sum two numbers",
args_schema=InputSchema,
func=sum_,
),
Tool(
name="subtract",
description="Subtract two numbers",
args_schema=InputSchema,
func=subtract,
),
Tool(
name="divide",
description="Divide two numbers",
args_schema=InputSchema,
func=divide,
),
Tool(
name="multiply",
description="Multiply two numbers",
args_schema=InputSchema,
func=multiply,
),
],
)


if __name__ == "__main__":

from crewai import Crew, Task

task = Task(
description="{history}",
expected_output="A helpful, concise reply to the user.",
agent=calculator_agent,
)
crew = Crew(agents=[calculator_agent], tasks=[task])

history = []
while True:
user_input = input("USER >>> ")
if user_input.lower() in ["exit", "quit"]:
break
history.append(f"User: {user_input}")
response = crew.kickoff(inputs={"history": history})
history.append(f"Agent: {response}")
print("AGENT >>>", response)

from pyagentspec.adapters.crewai import AgentSpecExporter

exporter = AgentSpecExporter()
agentspec_yaml = exporter.to_yaml(calculator_agent)
print(agentspec_yaml)
2 changes: 2 additions & 0 deletions docs/pyagentspec/source/_components/all_components.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@
"classes": [
{"path": "pyagentspec.adapters.autogen.AgentSpecExporter"},
{"path": "pyagentspec.adapters.autogen.AgentSpecLoader"},
{"path": "pyagentspec.adapters.crewai.AgentSpecExporter"},
{"path": "pyagentspec.adapters.crewai.AgentSpecLoader"},
{"path": "pyagentspec.adapters.langgraph.AgentSpecExporter"},
{"path": "pyagentspec.adapters.langgraph.AgentSpecLoader"}
]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions docs/pyagentspec/source/adapters/crewai.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
.. _crewaiadapter:

============================
Agent Spec Adapters - CrewAI
============================


.. figure:: ../_static/icons/crewai-adapter.jpg
:align: center
:scale: 18%
:alt: Agent Spec adapter for CrewAI

↑ With the **Agent Spec adapter for CrewAI**, you can easily import agents from external frameworks using Agent Spec and run them with CrewAI.

*CrewAI enables the design of collaborative AI agents and workflows, incorporating guardrails, memory,
and observability for production-ready multi-agent systems.*


Get started
===========

To get started, set up your Python environment (Python 3.10 to 3.13 required),
and then install the PyAgentSpec package with the CrewAI extension.


.. code-block:: bash

python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install "pyagentspec[crewai]"


You are now ready to use the adapter:

- Run Agent Spec configurations with CrewAI (see more details :ref:`below <spectocrewai>`)
- Convert CrewAI agents to Agent Spec (see more details :ref:`below <crewaitospec>`)



.. _spectocrewai:

Run Agent Spec configurations with CrewAI
=========================================


.. literalinclude:: ../code_examples/adapter_crewai_quickstart.py
:language: python
:start-after: .. start-agentspec_to_runtime
:end-before: .. end-agentspec_to_runtime


.. _crewaitospec:

Convert CrewAI agents to Agent Spec
===================================

.. literalinclude:: ../code_examples/adapter_crewai_quickstart.py
:language: python
:start-after: .. start-runtime_to_agentspec
:end-before: .. end-runtime_to_agentspec
9 changes: 9 additions & 0 deletions docs/pyagentspec/source/api/adapters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ LangGraph
.. _adapters_langgraph_loader:
.. autoclass:: pyagentspec.adapters.langgraph.AgentSpecLoader

CrewAI
------

.. _adapters_crewai_exporter:
.. autoclass:: pyagentspec.adapters.crewai.AgentSpecExporter

.. _adapters_crewai_loader:
.. autoclass:: pyagentspec.adapters.crewai.AgentSpecLoader

AutoGen
-------

Expand Down
8 changes: 8 additions & 0 deletions docs/pyagentspec/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ Agent Spec |release|
New features
^^^^^^^^^^^^

* **Added CrewAI adapter to pyagentspec:**

The CrewAI adapter is now available as part of ``pyagentspec``.
You can access its functionality through the ``pyagentspec.adapters.crewai`` subpackage.
It requires the ``crewai`` extra dependency to be installed.

For more information read the :doc:`API Reference <api/adapters>`.

* **MCP tools support in LangGraph adapter:**

The LangGraph adapter now supports Model Context Protocol (MCP) tools.
Expand Down
Loading