Skip to content

Commit 98dd0ca

Browse files
committed
Final changes
1 parent d45d5fd commit 98dd0ca

File tree

29 files changed

+200
-164
lines changed

29 files changed

+200
-164
lines changed

agent_apis/src/functions/weather.py

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

44
HTTP_OK = 200
55

@@ -21,6 +21,6 @@ async def weather() -> str:
2121
return str(data)
2222
error_message = f"Error: {response.status}"
2323
raise_exception(error_message)
24-
except Exception:
25-
log.error("Error: {e}")
26-
raise
24+
except Exception as e:
25+
error_message = f"Error: {e}"
26+
raise NonRetryableError(error_message) from e

agent_apis/src/workflows/multistep.py

Lines changed: 1 addition & 1 deletion
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, NonRetryableError
4+
from restack_ai.workflow import NonRetryableError, import_functions, log, workflow
55

66
with import_functions():
77
from src.functions.llm import FunctionInputParams, llm

agent_rag/src/agents/chat_rag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import timedelta
22

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

66
with import_functions():
77
from src.functions.llm_chat import LlmChatInput, Message, llm_chat

agent_rag/src/functions/lookup_sales.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pydantic import BaseModel
2-
from restack_ai.function import function, log
2+
from restack_ai.function import NonRetryableError, function, log
33

44

55
class SalesItem(BaseModel):
@@ -85,5 +85,5 @@ async def lookup_sales() -> str:
8585

8686
return str(items)
8787
except Exception as e:
88-
log.error("lookup_sales function failed", error=e)
89-
raise
88+
error_message = f"lookup_sales function failed: {e}"
89+
raise NonRetryableError(error_message) from e

agent_stream/src/functions/llm_chat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from openai import OpenAI
55
from pydantic import BaseModel, Field
6-
from restack_ai.function import function, log, stream_to_websocket
6+
from restack_ai.function import NonRetryableError, function, stream_to_websocket
77

88
from src.client import api_address
99

@@ -49,5 +49,5 @@ async def llm_chat(function_input: LlmChatInput) -> str:
4949
return await stream_to_websocket(api_address=api_address, data=response)
5050

5151
except Exception as e:
52-
log.error("llm_chat function failed", error=str(e))
53-
raise
52+
error_message = f"llm_chat function failed: {e}"
53+
raise NonRetryableError(error_message) from e

agent_telephony/twilio/agent_twilio/src/functions/livekit_dispatch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from livekit import api
55
from livekit.protocol.agent_dispatch import AgentDispatch
6-
from restack_ai.function import function, function_info, log
6+
from restack_ai.function import NonRetryableError, function, function_info
77

88

99
@dataclass
@@ -37,8 +37,8 @@ async def livekit_dispatch(function_input: LivekitDispatchInput) -> AgentDispatc
3737
await lkapi.aclose()
3838

3939
except Exception as e:
40-
log.error("livekit_dispatch function failed", error=str(e))
41-
raise
40+
error_message = f"livekit_dispatch function failed: {e}"
41+
raise NonRetryableError(error_message) from e
4242

4343
else:
4444
return dispatch

agent_telephony/twilio/agent_twilio/src/functions/livekit_room.py

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

33
from livekit import api
44
from livekit.api import CreateRoomRequest, Room
5-
from restack_ai.function import function, function_info, log
5+
from restack_ai.function import NonRetryableError, function, function_info
66

77

88
@function.defn()
@@ -27,8 +27,8 @@ async def livekit_room() -> Room:
2727
await lkapi.aclose()
2828

2929
except Exception as e:
30-
log.error("livekit_dispatch function failed", error=str(e))
31-
raise
30+
error_message = f"livekit_room function failed: {e}"
31+
raise NonRetryableError(error_message) from e
3232

3333
else:
3434
return room

agent_telephony/twilio/agent_twilio/src/functions/llm_chat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from openai import OpenAI
55
from pydantic import BaseModel, Field
6-
from restack_ai.function import function, log, stream_to_websocket
6+
from restack_ai.function import NonRetryableError, function, stream_to_websocket
77

88
from src.client import api_address
99

@@ -48,5 +48,5 @@ async def llm_chat(function_input: LlmChatInput) -> str:
4848
return await stream_to_websocket(api_address=api_address, data=response)
4949

5050
except Exception as e:
51-
log.error("llm_chat function failed", error=str(e))
52-
raise
51+
error_message = f"llm_chat function failed: {e}"
52+
raise NonRetryableError(error_message) from e

agent_telephony/vapi/agent_vapi/src/agents/agent.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import timedelta
22

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

66
with import_functions():
77
from src.functions.llm_chat import LlmChatInput, Message, llm_chat
@@ -32,27 +32,38 @@ async def messages(self, messages_event: MessagesEvent) -> list[Message]:
3232
log.info(f"Received message: {messages_event.messages}")
3333
self.messages.extend(messages_event.messages)
3434

35-
assistant_message = await agent.step(
36-
function=llm_chat,
37-
function_input=LlmChatInput(messages=self.messages),
38-
start_to_close_timeout=timedelta(seconds=120),
39-
)
40-
self.messages.append(Message(role="assistant", content=str(assistant_message)))
41-
return self.messages
35+
try:
36+
assistant_message = await agent.step(
37+
function=llm_chat,
38+
function_input=LlmChatInput(messages=self.messages),
39+
start_to_close_timeout=timedelta(seconds=120),
40+
)
41+
except Exception as e:
42+
error_message = f"llm_chat function failed: {e}"
43+
raise NonRetryableError(error_message) from e
44+
else:
45+
self.messages.append(Message(role="assistant", content=str(assistant_message)))
46+
return self.messages
4247

4348
@agent.event
4449
async def call(self, call_input: CallInput) -> None:
4550
log.info("Call", call_input=call_input)
4651
assistant_id = call_input.assistant_id
4752
phone_number = call_input.phone_number
4853

49-
return await agent.step(
50-
function=vapi_call,
51-
function_input=VapiCallInput(
52-
assistant_id=assistant_id,
53-
phone_number=phone_number,
54-
),
55-
)
54+
try:
55+
result = agent.step(
56+
function=vapi_call,
57+
function_input=VapiCallInput(
58+
assistant_id=assistant_id,
59+
phone_number=phone_number,
60+
),
61+
)
62+
except Exception as e:
63+
error_message = f"vapi_call function failed: {e}"
64+
raise NonRetryableError(error_message) from e
65+
else:
66+
return result
5667

5768
@agent.event
5869
async def end(self, end: EndEvent) -> EndEvent:

agent_telephony/vapi/agent_vapi/src/functions/llm_chat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from openai import OpenAI
55
from pydantic import BaseModel, Field
6-
from restack_ai.function import function, log, stream_to_websocket
6+
from restack_ai.function import NonRetryableError, function, stream_to_websocket
77

88
from src.client import api_address
99

@@ -48,5 +48,5 @@ async def llm_chat(function_input: LlmChatInput) -> str:
4848
return await stream_to_websocket(api_address=api_address, data=response)
4949

5050
except Exception as e:
51-
log.error("llm_chat function failed", error=str(e))
52-
raise
51+
error_message = f"llm_chat function failed: {e}"
52+
raise NonRetryableError(error_message) from e

0 commit comments

Comments
 (0)