Agent Spec Adapters - WayFlow#
↑ With the Agent Spec adapter for WayFlow, you can easily import agents from external frameworks using Agent Spec and run them with WayFlow.#
WayFlow is the reference framework for Agent Spec, provides modular components for developing AI-powered assistants, supporting both workflow-based and agent-style applications.
Get started#
To get started, set up your Python environment (Python 3.10 or newer required), and then install the PyAgentSpec package as well as WayFlowCore.
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install pyagentspec wayflowcore
You are now ready to use the adapter:
Run Agent Spec configurations with WayFlow#
# Create a Agent Spec agent
from pyagentspec.agent import Agent
from pyagentspec.llms.openaicompatibleconfig import OpenAiCompatibleConfig
from pyagentspec.property import FloatProperty
from pyagentspec.tools import ServerTool
subtraction_tool = ServerTool(
name="subtraction-tool",
description="subtract two numbers together",
inputs=[FloatProperty(title="a"), FloatProperty(title="b")],
outputs=[FloatProperty(title="difference")],
)
agentspec_llm_config = OpenAiCompatibleConfig(
name="llama-3.3-70b-instruct",
model_id="/storage/models/Llama-3.3-70B-Instruct",
url="url.to.my.llm",
)
agentspec_agent = Agent(
name="agentspec_tools_test",
description="agentspec_tools_test",
llm_config=agentspec_llm_config,
system_prompt="Perform subtraction with the given tool.",
tools=[subtraction_tool],
)
# Export the Agent Spec configuration
from pyagentspec.serialization import AgentSpecSerializer
agentspec_config = AgentSpecSerializer().to_json(agentspec_agent)
# Load and run the Agent Spec configuration with WayFlow
from wayflowcore.agentspec import AgentSpecLoader
def subtract(a: float, b: float) -> float:
return a - b
async def main():
converter = AgentSpecLoader(tool_registry={"subtraction-tool": subtract})
assistant = converter.load_json(agentspec_config)
conversation = assistant.start_conversation()
while True:
user_input = input("USER >> ")
if user_input == "exit":
break
conversation.append_user_message(user_input)
await conversation.execute_async()
last = conversation.get_last_message()
print(f"AGENT >> {last.content}")
# anyio.run(main)
# USER >> Compute 987654321-123456789
# AGENT >> The result of the subtraction is 864197532.
Convert WayFlow agents to Agent Spec#
# Create a WayFlow Agent
from wayflowcore.agent import Agent
from wayflowcore.models import OpenAICompatibleModel
from wayflowcore.tools import tool
@tool("subtraction-tool", description_mode="only_docstring")
def subtraction_tool(a: float, b: float) -> float:
"""subtract two numbers together"""
return a - b
llm = OpenAICompatibleModel(
name="llama-3.3-70b-instruct",
model_id="/storage/models/Llama-3.3-70B-Instruct",
base_url="url.to.my.llm",
)
wayflow_agent = Agent(
name="wayflow_agent",
description="Simple agent with a tool.",
llm=llm,
custom_instruction="Perform subtraction with the given tool.",
tools=[subtraction_tool],
)
# Convert to Agent Spec
from wayflowcore.agentspec import AgentSpecExporter
agentspec_config = AgentSpecExporter().to_json(wayflow_agent)