# 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 CrewAI
import os
os.environ["CREWAI_DISABLE_TELEMETRY"] = "true"
from crewai import Crew, Task
from pyagentspec.adapters.crewai import AgentSpecLoader
def subtract(a: float, b: float) -> float:
return a - b
async def main():
loader = AgentSpecLoader(tool_registry={"subtraction-tool": subtract})
assistant = loader.load_json(agentspec_config)
while True:
task = Task(
description="{user_input}",
expected_output="A helpful, concise reply to the user.",
agent=assistant,
async_execution=True
)
crew = Crew(agents=[assistant], tasks=[task])
user_input = input("USER >> ")
if user_input == "exit":
break
response = await crew.kickoff_async(inputs={"user_input": user_input})
print(f"AGENT >> {response}")
# anyio.run(main)
# USER >> Compute 987654321-123456789
# AGENT >> 864197532