Skip to content

Commit

Permalink
improve: add error log for model call
Browse files Browse the repository at this point in the history
  • Loading branch information
hyacinthus committed Jan 26, 2025
1 parent 2040fd2 commit b3a8f46
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/core/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,11 @@ def default_memory_manager(state: AgentState) -> AgentState:
# Define the function that calls the model
def call_model(state: AgentState, config: RunnableConfig) -> AgentState:
_validate_chat_history(state["messages"])
response = model_runnable.invoke(state, config)
try:
response = model_runnable.invoke(state, config)
except Exception as e:
logger.error(f"Error in call model: {e}")
raise e
has_tool_calls = isinstance(response, AIMessage) and response.tool_calls
all_tools_return_direct = (
all(call["name"] in should_return_direct for call in response.tool_calls)
Expand Down Expand Up @@ -342,7 +346,11 @@ def call_model(state: AgentState, config: RunnableConfig) -> AgentState:

async def acall_model(state: AgentState, config: RunnableConfig) -> AgentState:
_validate_chat_history(state["messages"])
response = await model_runnable.ainvoke(state, config)
try:
response = await model_runnable.ainvoke(state, config)
except Exception as e:
logger.error(f"Error in async call model: {e}")
raise e
has_tool_calls = isinstance(response, AIMessage) and response.tool_calls
all_tools_return_direct = (
all(call["name"] in should_return_direct for call in response.tool_calls)
Expand Down

0 comments on commit b3a8f46

Please sign in to comment.