Skip to content

Commit 320f746

Browse files
committed
Update agent-apis example
1 parent 223f89d commit 320f746

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

agent_apis/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dependencies = [
1111
"python-dotenv==1.0.1",
1212
"openai>=1.61.0",
1313
"aiohttp>=3.11.12",
14-
"restack-ai>=0.0.77",
14+
"restack-ai>=0.0.78",
1515
]
1616

1717
[project.scripts]
Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import timedelta
22

33
from pydantic import BaseModel, Field
4-
from restack_ai.workflow import import_functions, log, workflow
4+
from restack_ai.workflow import import_functions, log, workflow, NonRetryableError
55

66
with import_functions():
77
from src.functions.llm import FunctionInputParams, llm
@@ -20,20 +20,28 @@ async def run(self, workflow_input: WorkflowInputParams) -> dict:
2020
user_content = f"Greet this person {workflow_input.name}"
2121

2222
# Step 1 get weather data
23-
weather_data = await workflow.step(
24-
function=weather, start_to_close_timeout=timedelta(seconds=120)
25-
)
26-
27-
# Step 2 Generate greeting with LLM based on name and weather data
28-
29-
llm_message = await workflow.step(
30-
function=llm,
31-
function_input=FunctionInputParams(
32-
system_content=f"You are a personal assitant and have access to weather data {weather_data}. Always greet person with relevant info from weather data",
33-
user_content=user_content,
34-
model="gpt-4o-mini",
35-
),
36-
start_to_close_timeout=timedelta(seconds=120),
37-
)
38-
log.info("MultistepWorkflow completed", llm_message=llm_message)
39-
return {"message": llm_message, "weather": weather_data}
23+
try:
24+
weather_data = await workflow.step(
25+
weather, start_to_close_timeout=timedelta(seconds=120)
26+
)
27+
except Exception as e:
28+
error_message = f"Error during weather: {e}"
29+
raise NonRetryableError(error_message) from e
30+
else:
31+
# Step 2 Generate greeting with LLM based on name and weather data
32+
try:
33+
llm_message = await workflow.step(
34+
function=llm,
35+
function_input=FunctionInputParams(
36+
system_content=f"You are a personal assitant and have access to weather data {weather_data}. Always greet person with relevant info from weather data",
37+
user_content=user_content,
38+
model="gpt-4o-mini",
39+
),
40+
start_to_close_timeout=timedelta(seconds=120),
41+
)
42+
except Exception as e:
43+
error_message = f"Error during llm: {e}"
44+
raise NonRetryableError(error_message) from e
45+
else:
46+
log.info("MultistepWorkflow completed", llm_message=llm_message)
47+
return {"message": llm_message, "weather": weather_data}

0 commit comments

Comments
 (0)