From 889bd7b867ead5d773d4985ccfd153fba4773613 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 30 Apr 2025 20:21:27 +0000 Subject: [PATCH 1/3] Update Python templates for async and agent-to-agent communication Co-Authored-By: jhaynie@agentuity.com --- common/py/anthropic.py | 6 +++--- common/py/crewai/agent.py | 3 ++- common/py/langchain/openai.py | 2 +- common/py/litellm.py | 4 ++-- common/py/llamaindex/openai.py | 2 +- common/py/openai.py | 6 +++--- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/common/py/anthropic.py b/common/py/anthropic.py index 16d1140..3018436 100644 --- a/common/py/anthropic.py +++ b/common/py/anthropic.py @@ -1,11 +1,11 @@ from agentuity import AgentRequest, AgentResponse, AgentContext -from anthropic import Anthropic +from anthropic import AsyncAnthropic -client = Anthropic() +client = AsyncAnthropic() async def run(request: AgentRequest, response: AgentResponse, context: AgentContext): - result = client.messages.create( + result = await client.messages.create( max_tokens=1024, messages=[ { diff --git a/common/py/crewai/agent.py b/common/py/crewai/agent.py index 5539ba9..e508c1e 100644 --- a/common/py/crewai/agent.py +++ b/common/py/crewai/agent.py @@ -4,5 +4,6 @@ async def run(request: AgentRequest, response: AgentResponse, context: AgentContext): inputs = {"topic": request.data.text or "AI LLMs"} - result = MyCrew().crew().kickoff(inputs=inputs) + crew = MyCrew().crew() + result = await crew.akickoff(inputs=inputs) return response.text(str(result)) diff --git a/common/py/langchain/openai.py b/common/py/langchain/openai.py index 8633ec9..73abdf6 100644 --- a/common/py/langchain/openai.py +++ b/common/py/langchain/openai.py @@ -18,6 +18,6 @@ async def run(request: AgentRequest, response: AgentResponse, context: AgentCont ) output_parser = StrOutputParser() chain = prompt | llm | output_parser - result = chain.invoke({"input": request.data.text}) + result = await chain.ainvoke({"input": request.data.text or "Tell me about AI"}) return response.text(result) diff --git a/common/py/litellm.py b/common/py/litellm.py index 82e351f..eaa16b0 100644 --- a/common/py/litellm.py +++ b/common/py/litellm.py @@ -1,8 +1,8 @@ -from litellm import completion +from litellm import acompletion from agentuity import AgentRequest, AgentResponse, AgentContext async def run(request: AgentRequest, response: AgentResponse, context: AgentContext): messages = [{"content": request.data.text or "Hello, how are you?", "role": "user"}] - result = completion(model="openai/gpt-4o", messages=messages) + result = await acompletion(model="openai/gpt-4o", messages=messages) return response.text(result.choices[0].message.content) diff --git a/common/py/llamaindex/openai.py b/common/py/llamaindex/openai.py index 5ff18ae..7cb99f1 100644 --- a/common/py/llamaindex/openai.py +++ b/common/py/llamaindex/openai.py @@ -18,5 +18,5 @@ def multiply(a: float, b: float) -> float: async def run(request: AgentRequest, response: AgentResponse, context: AgentContext): - result = await agent.run(request.data.text or "What is 1234 * 4567?") + result = await agent.arun(request.data.text or "What is 1234 * 4567?") return response.text(str(result)) diff --git a/common/py/openai.py b/common/py/openai.py index d68080d..a4d869c 100644 --- a/common/py/openai.py +++ b/common/py/openai.py @@ -1,11 +1,11 @@ -from openai import OpenAI +from openai import AsyncOpenAI from agentuity import AgentRequest, AgentResponse, AgentContext -client = OpenAI() +client = AsyncOpenAI() async def run(request: AgentRequest, response: AgentResponse, context: AgentContext): - chat_completion = client.chat.completions.create( + chat_completion = await client.chat.completions.create( messages=[ { "role": "system", From b308252fe58ca0e3dc5ad7c25bb90c80aad3c309 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 30 Apr 2025 20:27:20 +0000 Subject: [PATCH 2/3] Update request.data.text to await request.data.text() in all templates Co-Authored-By: jhaynie@agentuity.com --- common/py/anthropic.py | 2 +- common/py/crewai/agent.py | 2 +- common/py/langchain/openai.py | 2 +- common/py/litellm.py | 2 +- common/py/llamaindex/openai.py | 2 +- common/py/openai.py | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/common/py/anthropic.py b/common/py/anthropic.py index 3018436..ed7e737 100644 --- a/common/py/anthropic.py +++ b/common/py/anthropic.py @@ -10,7 +10,7 @@ async def run(request: AgentRequest, response: AgentResponse, context: AgentCont messages=[ { "role": "user", - "content": request.data.text or "Hello, Claude", + "content": await request.data.text() or "Hello, Claude", } ], model="claude-3-5-sonnet-latest", diff --git a/common/py/crewai/agent.py b/common/py/crewai/agent.py index e508c1e..f6eeaff 100644 --- a/common/py/crewai/agent.py +++ b/common/py/crewai/agent.py @@ -3,7 +3,7 @@ async def run(request: AgentRequest, response: AgentResponse, context: AgentContext): - inputs = {"topic": request.data.text or "AI LLMs"} + inputs = {"topic": await request.data.text() or "AI LLMs"} crew = MyCrew().crew() result = await crew.akickoff(inputs=inputs) return response.text(str(result)) diff --git a/common/py/langchain/openai.py b/common/py/langchain/openai.py index 73abdf6..68708c7 100644 --- a/common/py/langchain/openai.py +++ b/common/py/langchain/openai.py @@ -18,6 +18,6 @@ async def run(request: AgentRequest, response: AgentResponse, context: AgentCont ) output_parser = StrOutputParser() chain = prompt | llm | output_parser - result = await chain.ainvoke({"input": request.data.text or "Tell me about AI"}) + result = await chain.ainvoke({"input": await request.data.text() or "Tell me about AI"}) return response.text(result) diff --git a/common/py/litellm.py b/common/py/litellm.py index eaa16b0..20adc20 100644 --- a/common/py/litellm.py +++ b/common/py/litellm.py @@ -3,6 +3,6 @@ async def run(request: AgentRequest, response: AgentResponse, context: AgentContext): - messages = [{"content": request.data.text or "Hello, how are you?", "role": "user"}] + messages = [{"content": await request.data.text() or "Hello, how are you?", "role": "user"}] result = await acompletion(model="openai/gpt-4o", messages=messages) return response.text(result.choices[0].message.content) diff --git a/common/py/llamaindex/openai.py b/common/py/llamaindex/openai.py index 7cb99f1..95b2f85 100644 --- a/common/py/llamaindex/openai.py +++ b/common/py/llamaindex/openai.py @@ -18,5 +18,5 @@ def multiply(a: float, b: float) -> float: async def run(request: AgentRequest, response: AgentResponse, context: AgentContext): - result = await agent.arun(request.data.text or "What is 1234 * 4567?") + result = await agent.arun(await request.data.text() or "What is 1234 * 4567?") return response.text(str(result)) diff --git a/common/py/openai.py b/common/py/openai.py index a4d869c..0aaf6df 100644 --- a/common/py/openai.py +++ b/common/py/openai.py @@ -13,7 +13,7 @@ async def run(request: AgentRequest, response: AgentResponse, context: AgentCont }, { "role": "user", - "content": request.data.text or "Why is the sky blue?", + "content": await request.data.text() or "Why is the sky blue?", }, ], model="gpt-4o", From 7c14d95b2dd849eac753ed16d33b3ded42a8055a Mon Sep 17 00:00:00 2001 From: Jeff Haynie Date: Wed, 30 Apr 2025 21:26:19 -0500 Subject: [PATCH 3/3] fixes from testing --- common/py/crewai/agent.py | 2 +- common/py/llamaindex/openai.py | 2 +- python-uv/templates.yaml | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/common/py/crewai/agent.py b/common/py/crewai/agent.py index f6eeaff..4b13986 100644 --- a/common/py/crewai/agent.py +++ b/common/py/crewai/agent.py @@ -5,5 +5,5 @@ async def run(request: AgentRequest, response: AgentResponse, context: AgentContext): inputs = {"topic": await request.data.text() or "AI LLMs"} crew = MyCrew().crew() - result = await crew.akickoff(inputs=inputs) + result = await crew.kickoff_async(inputs=inputs) return response.text(str(result)) diff --git a/common/py/llamaindex/openai.py b/common/py/llamaindex/openai.py index 95b2f85..4f2a96b 100644 --- a/common/py/llamaindex/openai.py +++ b/common/py/llamaindex/openai.py @@ -18,5 +18,5 @@ def multiply(a: float, b: float) -> float: async def run(request: AgentRequest, response: AgentResponse, context: AgentContext): - result = await agent.arun(await request.data.text() or "What is 1234 * 4567?") + result = await agent.run(await request.data.text() or "What is 1234 * 4567?") return response.text(str(result)) diff --git a/python-uv/templates.yaml b/python-uv/templates.yaml index 06c5965..4ab5ba1 100644 --- a/python-uv/templates.yaml +++ b/python-uv/templates.yaml @@ -52,7 +52,8 @@ args: - add - --quiet - - llama-index + - llama-index==0.12.33 + - llama-index-core==0.12.33 - action: create_file filename: "agents/{{ .AgentName | safe_filename }}/agent.py" from: "common/py/llamaindex/openai.py"