Skip to content

Commit b9692ab

Browse files
committed
Update agent-video example
1 parent 9da3da8 commit b9692ab

File tree

6 files changed

+46
-35
lines changed

6 files changed

+46
-35
lines changed

agent_video/pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ dependencies = [
88
"openai>=1.59.9",
99
"pipecat-ai[daily,deepgram,openai,silero,cartesia]>=0.0.58",
1010
"python-dotenv>=1.0.1",
11-
"restack-ai>=0.0.77",
1211
"pydantic>=2.10.6",
1312
"watchfiles>=1.0.4",
13+
"restack-ai>=0.0.78",
1414
]
1515

1616
[project.scripts]
@@ -23,6 +23,9 @@ include = ["src"]
2323
[tool.hatch.build.targets.wheel]
2424
include = ["src"]
2525

26+
[tool.uv.sources]
27+
restack-ai = { path = "../../../sdk/engine/libraries/python/dist/restack_ai-0.0.78-py3-none-any.whl" }
28+
2629
[build-system]
2730
requires = ["hatchling"]
2831
build-backend = "hatchling.build"

agent_video/src/agents/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from restack_ai.agent import agent, import_functions, log
55

66
with import_functions():
7-
from src.functions.llm_chat import LlmChatInput, Message, llm_chat
87
from src.functions.context_docs import context_docs
8+
from src.functions.llm_chat import LlmChatInput, Message, llm_chat
99

1010
class MessagesEvent(BaseModel):
1111
messages: list[Message]

agent_video/src/functions/context_docs.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
from restack_ai.function import function, log
21
import aiohttp
2+
from restack_ai.function import function, log
33

44

55
async def fetch_content_from_url(url: str) -> str:
66
async with aiohttp.ClientSession() as session:
77
async with session.get(url) as response:
88
if response.status == 200:
99
return await response.text()
10-
else:
11-
log.error("Failed to fetch content", status=response.status)
12-
raise Exception(f"Failed to fetch content: {response.status}")
10+
log.error("Failed to fetch content", status=response.status)
11+
raise Exception(f"Failed to fetch content: {response.status}")
1312

1413

1514
@function.defn()
1615
async def context_docs() -> str:
1716
try:
1817
docs_content = await fetch_content_from_url("https://docs.restack.io/llms-full.txt")
1918
log.info("Fetched content from URL", content=len(docs_content))
20-
19+
2120
return docs_content
2221

2322
except Exception as e:

agent_video/src/functions/pipeline.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from pipecat.services.tavus import TavusVideoService
2222
from pipecat.transports.services.daily import DailyParams, DailyTransport
2323
from pydantic import BaseModel
24-
from restack_ai.function import FunctionFailure, function, log
24+
from restack_ai.function import NonRetryableError, function, log
2525

2626
load_dotenv(override=True)
2727

@@ -159,7 +159,7 @@ async def run_pipeline():
159159
)
160160
# Cancel the pipeline task if an error occurs within the pipeline runner.
161161
await task.cancel()
162-
raise e
162+
raise NonRetryableError(f"Pipecat pipeline failed: {e}") from e
163163

164164
# Launch the pipeline runner as a background task so it doesn't block the return.
165165
asyncio.create_task(run_pipeline())
@@ -170,4 +170,4 @@ async def run_pipeline():
170170
return room_url
171171
except Exception as e:
172172
log.error("Pipecat pipeline failed", error=e)
173-
raise FunctionFailure(f"Pipecat pipeline failed: {e}", non_retryable=True)
173+
raise NonRetryableError(f"Pipecat pipeline failed: {e}") from e

agent_video/src/services.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
from src.agents.agent import AgentVideo
99
from src.client import client
10+
from src.functions.context_docs import context_docs
1011
from src.functions.llm_chat import llm_chat
1112
from src.functions.pipeline import pipecat_pipeline
1213
from src.workflows.room import RoomWorkflow
13-
from src.functions.context_docs import context_docs
1414

1515

1616
async def main() -> None:

agent_video/src/workflows/room.py

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from pydantic import BaseModel
44
from restack_ai.workflow import (
5+
NonRetryableError,
56
ParentClosePolicy,
67
import_functions,
78
log,
@@ -24,27 +25,35 @@ class RoomWorkflow:
2425
@workflow.run
2526
async def run(self) -> RoomWorkflowOutput:
2627
agent_id = f"{workflow_info().workflow_id}-agent"
27-
agent = await workflow.child_start(
28-
agent=AgentVideo,
29-
agent_id=agent_id,
30-
start_to_close_timeout=timedelta(minutes=20),
31-
parent_close_policy=ParentClosePolicy.ABANDON,
32-
)
33-
34-
log.info("Agent started", agent=agent)
35-
36-
room_url = await workflow.step(
37-
function=pipecat_pipeline,
38-
function_input=PipecatPipelineInput(
39-
agent_name=AgentVideo.__name__,
40-
agent_id=agent.id,
41-
agent_run_id=agent.run_id,
42-
),
43-
start_to_close_timeout=timedelta(minutes=20),
44-
)
45-
46-
log.info("Pipecat pipeline started")
47-
48-
log.info("RoomWorkflow completed", room_url=room_url)
49-
50-
return RoomWorkflowOutput(room_url=room_url)
28+
try:
29+
agent = await workflow.child_start(
30+
agent=AgentVideo,
31+
agent_id=agent_id,
32+
start_to_close_timeout=timedelta(minutes=20),
33+
parent_close_policy=ParentClosePolicy.ABANDON,
34+
)
35+
except Exception as e:
36+
error_message = f"Error during child_start: {e}"
37+
raise NonRetryableError(error_message) from e
38+
else:
39+
log.info("Agent started", agent=agent)
40+
41+
try:
42+
room_url = await workflow.step(
43+
function=pipecat_pipeline,
44+
function_input=PipecatPipelineInput(
45+
agent_name=AgentVideo.__name__,
46+
agent_id=agent.id,
47+
agent_run_id=agent.run_id,
48+
),
49+
start_to_close_timeout=timedelta(minutes=20),
50+
)
51+
except Exception as e:
52+
error_message = f"Error during pipecat_pipeline: {e}"
53+
raise NonRetryableError(error_message) from e
54+
else:
55+
log.info("Pipecat pipeline started")
56+
57+
log.info("RoomWorkflow completed", room_url=room_url)
58+
59+
return RoomWorkflowOutput(room_url=room_url)

0 commit comments

Comments
 (0)