Skip to content

Fix/catch nil panic - #216

Merged
mudler merged 2 commits into
mudler:mainfrom
alixanderthegreat:fix/catch-nil-panic
Jun 23, 2025
Merged

mudler merged 2 commits into
mudler:mainfrom
alixanderthegreat:fix/catch-nil-panic

Conversation

@alixanderthegreat

@alixanderthegreat alixanderthegreat commented Jun 23, 2025

Copy link
Copy Markdown
Contributor

While testing, found a nice crash

panic: runtime error: invalid memory address or nil pointer dereference                                                                                                                                                         
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0xfbb105]                                                                                                                                                         
                                                                                                                                                                                                                                
goroutine 68 [running]:                                                                                                                                                                                                         
github.com/mudler/LocalAGI/core/agent.(*Agent).generateParameters(0xc0005ba800, 0xc000386210, {0x1a0cba8, 0x72f}, {0x0, 0x0}, {0xc0002b8b40, 0x3, 0x3}, {0xc0003202c0, ...}, ...)                                               
        /home/user/LocalAGI/core/agent/actions.go:240 +0x65                                                                                                                                                                     
github.com/mudler/LocalAGI/core/agent.(*Agent).handlePlanning(0xc0005ba800, {0x72f?, 0x1fa0a20?}, 0xc000386210, {0x1fa0a20, 0xc000692528}, 0xc00033d200, {0xc0005b2b00, 0x506}, {0x1a0cba8, ...}, ...)                          
        /home/user/LocalAGI/core/agent/actions.go:368 +0xbae                                                                                                                                                                    
github.com/mudler/LocalAGI/core/agent.(*Agent).consumeJob(0xc0005ba800, 0xc000386210, {0x1986edf, 0x4}, 0x5)                                                                                                                    
        /home/user/LocalAGI/core/agent/agent.go:794 +0x1ef8                                                                                                                                                                     
github.com/mudler/LocalAGI/core/agent.(*Agent).run(0xc0005ba800, 0xc000318070)
        /home/user/LocalAGI/core/agent/agent.go:1182 +0xfd
github.com/mudler/LocalAGI/core/agent.(*Agent).Run.func1()
        /home/user/LocalAGI/core/agent/agent.go:1160 +0x3a
created by github.com/mudler/LocalAGI/core/agent.(*Agent).Run in goroutine 38
        /home/user/LocalAGI/core/agent/agent.go:1159 +0x19b

Added a robust nil catcher system.

@mudler mudler left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mudler

mudler commented Jun 23, 2025

Copy link
Copy Markdown
Owner

Although, it shouldn't reach that point, but good code coverage. Can you reproduce it ?

@mudler
mudler merged commit 86659e7 into mudler:main Jun 23, 2025
@alixanderthegreat

alixanderthegreat commented Jun 26, 2025

Copy link
Copy Markdown
Contributor Author

Thanks for the merge 👍

I haven't been able to reproduce the panic with the nil catcher ; and I guess I was under the impression that xlog.Error() took the %s token 🤦

However... it is interesting to see that it is trying to create actions: 👇

// HERE IS THE REPRO WHERE THE NIL CATCH WAS NEEDED
time=2025-06-26T10:42:59.586-06:00 level=ERROR msg="Action not found: %s" "Analyze competitor pricing strategies"="source=[file=/home/user/LocalAGI/core/agent/actions.go L=369]"
time=2025-06-26T10:42:59.586-06:00 level=ERROR msg="error handling planning" error="action Analyze competitor pricing strategies not found" source.file=/home/user/LocalAGI/core/agent/agent.go source.L=796

Here is the log stack if you are intrigued to see the full flow:

time=2025-06-26T10:38:30.544-06:00 level=DEBUG msg="Agent Ask()" agent=node model=amoral-gemma3-1b-v2 source.file=/home/user/LocalAGI/core/agent/agent.go source.L=162
time=2025-06-26T10:38:30.544-06:00 level=DEBUG msg="Agent Execute()" agent=node model=amoral-gemma3-1b-v2 source.file=/home/user/LocalAGI/core/agent/agent.go source.L=187
time=2025-06-26T10:38:30.544-06:00 level=DEBUG msg="Agent is consuming a job" agent=node job="&{Result:0xc000476400 ReasoningCallback:0xfe03c0 ResultCallback:0xfdfca0 ConversationHistory:[{Role:user Content:Help me plan out 
my day. Refusal: MultiContent:[] Name: ReasoningContent: FunctionCall:<nil> ToolCalls:[] ToolCallID:}] UUID:f5cfc054-f00c-428f-8738-16aaadbd8c42 Metadata:map[] DoneFilter:false pastActions:[] nextAction:<nil> nextActionParam
s:<nil> nextActionReasoning: context:0xc00012c1e0 cancel:0x57f720 Obs:0xc000110c60}" source.file=/home/user/LocalAGI/core/agent/agent.go source.L=1181
time=2025-06-26T10:38:30.544-06:00 level=DEBUG msg="No filters" source.file=/home/user/LocalAGI/core/agent/agent.go source.L=514
time=2025-06-26T10:38:30.544-06:00 level=INFO msg="[Knowledge Base Lookup] Last user message" agent=node message="Help me plan out my day." lastMessage="&{Role:user Content:Help me plan out my day. Refusal: MultiContent:[] N
ame: ReasoningContent: FunctionCall:<nil> ToolCalls:[] ToolCallID:}" source.file=/home/user/LocalAGI/core/agent/knowledgebase.go source.L=34

// the LOCALRECALL was not up and running yet...
time=2025-06-26T10:38:30.561-06:00 level=INFO msg="Error finding similar strings inside KB:" error="Post \"http://127.0.0.1:8080/api/collections/node/search\": dial tcp 127.0.0.1:8080: connect: connection refused" so
urce.file=/home/user/LocalAGI/core/agent/knowledgebase.go source.L=49
time=2025-06-26T10:38:30.561-06:00 level=INFO msg="[Knowledge Base Lookup] No similar strings found in KB" agent=node source.file=/home/user/LocalAGI/core/agent/knowledgebase.go source.L=59


time=2025-06-26T10:38:30.561-06:00 level=DEBUG msg="[pickAction] picking action starts" messages="[{Role:user Content:Help me plan out my day. Refusal: MultiContent:[] Name: ReasoningContent: FunctionCall:<nil> ToolCalls:[] 
ToolCallID:}]" source.file=/home/user/LocalAGI/core/agent/actions.go source.L=493
time=2025-06-26T10:38:30.561-06:00 level=DEBUG msg="[pickAction] forcing reasoning" source.file=/home/user/LocalAGI/core/agent/actions.go source.L=527
time=2025-06-26T10:42:51.910-06:00 level=DEBUG msg="[pickAction] picking action" messages="[{Role:system Content:\nCurrent Time: 2025-06-26T10:38:30-06:00\nYour only task is to analyze the conversation and determine a goal a
nd the best tool to use, or just a final response if we have fullfilled the goal.\n\nGuidelines:\n1. Review the current state, what was done already and context\n2. Consider available tools and their purposes\n3. Plan your a
pproach carefully\n4. Explain your reasoning clearly\n\nWhen choosing actions:\n- Use \"reply\" or \"answer\" tools for direct responses\n- Select appropriate tools for specific tasks\n- Consider the impact of each action\n-
 Plan for potential challenges\n\nDecision Process:\n1. Analyze the situation\n2. Consider available options\n3. Choose the best course of action\n4. Explain your reasoning\n5. Execute the chosen action\n\nAvailable Tools:\n
- plan: Use it for situations that involves doing more actions in sequence.\n\n\n Refusal: MultiContent:[] Name: ReasoningContent: FunctionCall:<nil> ToolCalls:[] ToolCallID:} {Role:user Content:Help me plan out my day. Refu
sal: MultiContent:[] Name: ReasoningContent: FunctionCall:<nil> ToolCalls:[] ToolCallID:}]" source.file=/home/user/LocalAGI/core/agent/actions.go source.L=572
time=2025-06-26T10:42:51.910-06:00 level=DEBUG msg="[pickAction] actionsID" actionsID="[reply plan]" source.file=/home/user/LocalAGI/core/agent/actions.go source.L=579
time=2025-06-26T10:42:55.307-06:00 level=DEBUG msg="Decision response" response="{\"id\":\"e68a118c-2a23-4ef1-abce-d89ac280fa2a\",\"object\":\"chat.completion\",\"created\":1750956172,\"model\":\"amoral-gemma3-1b-v2\",\"choi
ces\":[{\"index\":0,\"message\":{\"role\":\"assistant\",\"tool_calls\":[{\"index\":0,\"id\":\"e68a118c-2a23-4ef1-abce-d89ac280fa2a\",\"type\":\"function\",\"function\":{\"name\":\"pick_tool\",\"arguments\":\"{\\\"reasoning\\
\":\\\"It is important to know what you want to achieve in order to plan your day effectively. Without a clear objective, it will be difficult to organize your time properly and maximize your productivity.\\\",\\\"tool\\\":\
\\"plan\\\"}\"}}]},\"finish_reason\":\"tool_calls\",\"content_filter_results\":{\"hate\":{\"filtered\":false},\"self_harm\":{\"filtered\":false},\"sexual\":{\"filtered\":false},\"violence\":{\"filtered\":false},\"jailbreak\"
:{\"filtered\":false,\"detected\":false},\"profanity\":{\"filtered\":false,\"detected\":false}}}],\"usage\":{\"prompt_tokens\":428,\"completion_tokens\":65,\"total_tokens\":493,\"prompt_tokens_details\":null,\"completion_tok
ens_details\":null},\"system_fingerprint\":\"\"}" source.file=/home/user/LocalAGI/core/agent/actions.go source.L=91
time=2025-06-26T10:42:55.307-06:00 level=DEBUG msg="[pickAction] chosenAction" chosenAction=&{plannables:[]} actionName=plan source.file=/home/user/LocalAGI/core/agent/actions.go source.L=616
time=2025-06-26T10:42:55.307-06:00 level=INFO msg="Generating parameters" agent=node action=plan reasoning="Okay, let's dive into planning your day.\n\nFirst, let's identify the overall goal you're aiming for. What do you wa
nt to accomplish today?" source.file=/home/user/LocalAGI/core/agent/agent.go source.L=726
time=2025-06-26T10:42:55.307-06:00 level=DEBUG msg="Action has properties" action=plan properties="map[goal:{Type:string Description:The goal of this plan Enum:[] Properties:map[] Required:[] Items:<nil> AdditionalProperties
:<nil> Nullable:false} subtasks:{Type:array Description:The subtasks to be executed Enum:[] Properties:map[] Required:[] Items:0xc000059680 AdditionalProperties:<nil> Nullable:false}]" source.file=/home/user/LocalAGI/core/ag
ent/actions.go source.L=243
time=2025-06-26T10:42:59.585-06:00 level=DEBUG msg="Decision response" response="{\"id\":\"73361d3d-813b-4d2f-921f-476cd9838a7e\",\"object\":\"chat.completion\",\"created\":1750956178,\"model\":\"amoral-gemma3-1b-v2\",\"choi
ces\":[{\"index\":0,\"message\":{\"role\":\"assistant\",\"tool_calls\":[{\"index\":0,\"id\":\"73361d3d-813b-4d2f-921f-476cd9838a7e\",\"type\":\"function\",\"function\":{\"name\":\"plan\",\"arguments\":\"{\\\"goal\\\":\\\"Inc
rease sales revenue by 10% in Q3\\\",\\\"subtasks\\\":[{\\\"action\\\":\\\"Analyze competitor pricing strategies\\\",\\\"reasoning\\\":\\\"Understand current market rates to identify potential opportunities for competitive a
dvantage\\\"},{\\\"action\\\":\\\"Develop a targeted marketing campaign\\\",\\\"reasoning\\\":\\\"Focus marketing efforts on customer segments most likely to purchase your product/service\\\"},{\\\"action\\\":\\\"Implement a
 loyalty program\\\",\\\"reasoning\\\":\\\"Reward repeat customers to foster brand loyalty and increase lifetime value\\\"}]}\"}}]},\"finish_reason\":\"tool_calls\",\"content_filter_results\":{\"hate\":{\"filtered\":false},\
"self_harm\":{\"filtered\":false},\"sexual\":{\"filtered\":false},\"violence\":{\"filtered\":false},\"jailbreak\":{\"filtered\":false,\"detected\":false},\"profanity\":{\"filtered\":false,\"detected\":false}}}],\"usage\":{\"
prompt_tokens\":590,\"completion_tokens\":118,\"total_tokens\":708,\"prompt_tokens_details\":null,\"completion_tokens_details\":null},\"system_fingerprint\":\"\"}" source.file=/home/user/LocalAGI/core/agent/actions.go source
.L=91
time=2025-06-26T10:42:59.585-06:00 level=INFO msg="Generated parameters" agent=node action=plan reasoning="Okay, let's dive into planning your day.\n\nFirst, let's identify the overall goal you're aiming for. What do you wan
t to accomplish today?" params="{\"goal\":\"Increase sales revenue by 10% in Q3\",\"subtasks\":[{\"action\":\"Analyze competitor pricing strategies\",\"reasoning\":\"Understand current market rates to identify potential oppo
rtunities for competitive advantage\"},{\"action\":\"Develop a targeted marketing campaign\",\"reasoning\":\"Focus marketing efforts on customer segments most likely to purchase your product/service\"},{\"action\":\"Implemen
t a loyalty program\",\"reasoning\":\"Reward repeat customers to foster brand loyalty and increase lifetime value\"}]}" source.file=/home/user/LocalAGI/core/agent/agent.go source.L=743
time=2025-06-26T10:42:59.585-06:00 level=INFO msg="Agent is thinking" agent=node reasoning="Okay, let's dive into planning your day.\n\nFirst, let's identify the overall goal you're aiming for. What do you want to accomplish
 today?" action=plan params="{\"goal\":\"Increase sales revenue by 10% in Q3\",\"subtasks\":[{\"action\":\"Analyze competitor pricing strategies\",\"reasoning\":\"Understand current market rates to identify potential opportu
nities for competitive advantage\"},{\"action\":\"Develop a targeted marketing campaign\",\"reasoning\":\"Focus marketing efforts on customer segments most likely to purchase your product/service\"},{\"action\":\"Implement a
 loyalty program\",\"reasoning\":\"Reward repeat customers to foster brand loyalty and increase lifetime value\"}]}" source.file=/home/user/LocalAGI/core/state/pool.go source.L=442
time=2025-06-26T10:42:59.585-06:00 level=DEBUG msg=[planning]... source.file=/home/user/LocalAGI/core/agent/actions.go source.L=330
time=2025-06-26T10:42:59.586-06:00 level=DEBUG msg="Calling agent result callback" source.file=/home/user/LocalAGI/core/state/pool.go source.L=474
time=2025-06-26T10:42:59.586-06:00 level=INFO msg="[Planning] starts" agent=node goal="Increase sales revenue by 10% in Q3" source.file=/home/user/LocalAGI/core/agent/actions.go source.L=350
time=2025-06-26T10:42:59.586-06:00 level=INFO msg="[Planning] subtask" agent=node action="Analyze competitor pricing strategies" reasoning="Understand current market rates to identify potential opportunities for competitive 
advantage" source.file=/home/user/LocalAGI/core/agent/actions.go source.L=352
time=2025-06-26T10:42:59.586-06:00 level=INFO msg="[Planning] subtask" agent=node action="Develop a targeted marketing campaign" reasoning="Focus marketing efforts on customer segments most likely to purchase your product/se
rvice" source.file=/home/user/LocalAGI/core/agent/actions.go source.L=352
time=2025-06-26T10:42:59.586-06:00 level=INFO msg="[Planning] subtask" agent=node action="Implement a loyalty program" reasoning="Reward repeat customers to foster brand loyalty and increase lifetime value" source.file=/home
/user/LocalAGI/core/agent/actions.go source.L=352
time=2025-06-26T10:42:59.586-06:00 level=INFO msg="[subtask] Generating parameters" agent=node action="Analyze competitor pricing strategies" reasoning="Okay, let's dive into planning your day.\n\nFirst, let's identify the o
verall goal you're aiming for. What do you want to accomplish today?" source.file=/home/user/LocalAGI/core/agent/actions.go source.L=361

// HERE IS THE REPRO WHERE THE NIL CATCH WAS NEEDED
time=2025-06-26T10:42:59.586-06:00 level=ERROR msg="Action not found: %s" "Analyze competitor pricing strategies"="source=[file=/home/user/LocalAGI/core/agent/actions.go L=369]"
time=2025-06-26T10:42:59.586-06:00 level=ERROR msg="error handling planning" error="action Analyze competitor pricing strategies not found" source.file=/home/user/LocalAGI/core/agent/agent.go source.L=796


time=2025-06-26T10:42:59.586-06:00 level=INFO msg="Computing reply" agent=node source.file=/home/user/LocalAGI/core/agent/agent.go source.L=926
time=2025-06-26T10:42:59.586-06:00 level=INFO msg="Reasoning, ask LLM for a reply" agent=node source.file=/home/user/LocalAGI/core/agent/agent.go source.L=959
time=2025-06-26T10:42:59.586-06:00 level=DEBUG msg=Conversation conversation="system: Reply to the user without using any tools or function calls. Just reply with the message.\nuser: Help me plan out my day.\nassistant: Erro
r handling planning: action Analyze competitor pricing strategies not found\n" source.file=/home/user/LocalAGI/core/agent/agent.go source.L=960
time=2025-06-26T10:43:00.660-06:00 level=INFO msg="Response from LLM" response="Let's start by looking at the top 10 competitors and their products, focusing on pricing, marketing, and customer reviews. Next, we'll create a 
competitive matrix outlining our product's strengths and weaknesses relative to these competitors. Then, we'll discuss the potential target market and develop a marketing plan." agent=node source.file=/home/user/LocalAGI/cor
e/agent/agent.go source.L=989
time=2025-06-26T10:43:00.660-06:00 level=INFO msg="Saving conversation" agent=node "conversation size"=4 source.file=/home/user/LocalAGI/core/agent/knowledgebase.go source.L=125
time=2025-06-26T10:43:00.660-06:00 level=DEBUG msg="Agent has finished" agent=node source.file=/home/user/LocalAGI/core/agent/agent.go source.L=189
time=2025-06-26T10:43:00.660-06:00 level=DEBUG msg="Agent has finished being asked" agent=node source.file=/home/user/LocalAGI/core/agent/agent.go source.L=164
time=2025-06-26T10:43:00.660-06:00 level=INFO msg="Response from agent" agent=node response="Let's start by looking at the top 10 competitors and their products, focusing on pricing, marketing, and customer reviews. Next, we
'll create a competitive matrix outlining our product's strengths and weaknesses relative to these competitors. Then, we'll discuss the potential target market and develop a marketing plan." source.file=/home/user/LocalAGI/w
ebui/app.go source.L=390
time=2025-06-26T10:43:01.702-06:00 level=DEBUG msg="Storing string in LocalRAG" collection=node fileName=2025-06-26-10-43-01-561a60f60c5d41fa808cb131773e6083.txt source.file=/home/user/LocalAGI/pkg/localrag/client.go source.
L=72
time=2025-06-26T10:43:02.224-06:00 level=DEBUG msg="Agent is now waiting for a new job" agent=node source.file=/home/user/LocalAGI/core/agent/agent.go source.L=1175

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants