Conversation
Review Summary by QodoFix lazy routing mode agent selection and instruction flow
WalkthroughsDescription• Fix lazy routing mode by checking if lazy routing agent ID exists before using it • Restructure routing logic to call appropriate instruction method based on routing mode • Simplify lazy routing agent update logic by removing redundant mode check • Reload agent after setting lazy routing agent ID to ensure correct agent state Diagramflowchart LR
A["Routing Agent Request"] --> B["Push Agent to Context"]
B --> C["Check Routing Mode"]
C --> D{"Lazy Mode & Agent ID Exists?"}
D -->|Yes| E["Load Lazy Agent"]
E --> F["Call InstructDirect"]
D -->|No| G["Call InstructLoop"]
H["UpdateLazyRoutingAgent"] --> I{"Update Flag True?"}
I -->|Yes| J["Set Lazy Agent ID"]
I -->|No| K["Skip Update"]
File Changes1. src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs
|
Code Review by Qodo
1. LoadAgent null dereferenced
|
| message.CurrentAgentId = lazyRoutingAgentId; | ||
| agent = await agentService.LoadAgent(message.CurrentAgentId); | ||
| await routing.Context.Push(message.CurrentAgentId, reason: "lazy routing", updateLazyRouting: false); | ||
| response = await routing.InstructDirect(agent, message, dialogs); |
There was a problem hiding this comment.
1. loadagent null dereferenced 📘 Rule violation ⛯ Reliability
In lazy routing, the code calls agentService.LoadAgent and then passes agent to routing.InstructDirect without guarding against LoadAgent returning null, which can cause a NullReferenceException at runtime. This violates the requirement to add explicit null/empty guards at provider/storage/state boundaries and return a safe fallback with logging.
Agent Prompt
## Issue description
`agentService.LoadAgent(message.CurrentAgentId)` can return `null`, but the lazy-routing path passes the possibly-null `agent` into `routing.InstructDirect`, which dereferences `agent` and can throw.
## Issue Context
`lazyRoutingAgentId` is loaded from conversation state and may be stale/invalid. `AgentService.LoadAgent` returns `null` when the ID is empty/invalid or the agent does not exist.
## Fix Focus Areas
- src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs[90-100]
- src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs[12-34]
- src/Infrastructure/BotSharp.Core/Routing/RoutingService.cs[29-47]
## Implementation notes
- Load into a separate variable (e.g., `lazyAgent`) and check for null.
- If null, log a clear warning (without sensitive content) and fall back to a safe behavior (e.g., keep the current `agent` and call `InstructLoop`, or return a generic failure response).
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
No description provided.