Skip to content

Commit

Permalink
Improved error handling in FluidAgent, enhanced stacktrace readabilit…
Browse files Browse the repository at this point in the history
…y, updated warning message in ToolInterface.
  • Loading branch information
Cvikli committed Feb 20, 2025
1 parent 5e8902f commit af90b9c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/agents/FluidAgent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ function work(agent::FluidAgent, conv; cache,
io=stdout,
tool_kwargs=Dict()
)

# Collect unique stop sequences from tools
stop_sequences = unique(String[stop_sequence(tool) for tool in agent.tools if has_stop_sequence(tool)])

Expand All @@ -171,7 +170,6 @@ function work(agent::FluidAgent, conv; cache,

cb = create(StreamCallbackTYPE(; io, on_start, on_error, highlight_enabled, process_enabled,
on_done = () -> begin
# Extracts tools in case anything is unclosed
process_enabled && extract_tool_calls("\n", extractor, io; kwargs=tool_kwargs, is_flush=true)
on_done()
end,
Expand Down Expand Up @@ -211,9 +209,10 @@ function work(agent::FluidAgent, conv; cache,
catch e
e isa InterruptException && rethrow(e)
# display(catch_backtrace())
@error "Error executing code block:" exception=(e, catch_backtrace())
@error "Error in fluidagent work" exception=(e, catch_backtrace())
on_error(e)
content = "Error: $(sprint(showerror, e))\n\nStacktrace: $(sprint(show, catch_backtrace(e)))"

content = "Error: $(sprint(showerror, e))\n\nStacktrace:\n$(join(string.(stacktrace(catch_backtrace())), "\n"))"
push_message!(conv, create_AI_message(content))
return (;
content,
Expand Down
2 changes: 1 addition & 1 deletion src/tools/ToolInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ is_cancelled(tool::AbstractTool) = false
"""
Usually stop_sequence and toolname are static for type
"""
toolname(tool::Type{<:AbstractTool})::String = (@warn "Unimplemented \"toolname\" for $(tool)"; return "")
toolname(tool::Type{<:AbstractTool})::String = (@warn "Unimplemented \"toolname\" for $(tool) $(stacktrace())"; return "")
toolname(tool::AbstractTool)::String = toolname(typeof(tool))
stop_sequence(::Type{<:AbstractTool})::String = (@warn "Unimplemented \"stop_sequence\" for $(typeof(tool))"; return "")
stop_sequence(tool::AbstractTool)::String = stop_sequence(typeof(tool))
Expand Down

0 comments on commit af90b9c

Please sign in to comment.