Repository navigation
fix(agent): enable single-component debug for Agent in Go backend - #16606
Conversation
- Generate input_form dynamically when DSL lacks static one - Inject tenant_id into debug CanvasState for LLM credential resolution
📝 WalkthroughWalkthroughThe PR modifies the agent component handler to add a runtime fallback for resolving a component's input form when the DSL lacks it, and sets tenant_id in the debug canvas state prior to component invocation. ChangesAgent Component Handler Updates
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant AgentHandler
participant DSL
participant RuntimeFactory
participant Component
Client->>AgentHandler: GetComponentInputForm request
AgentHandler->>DSL: ExtractComponentInputForm
alt input_form present
DSL-->>AgentHandler: schema
else input_form missing
AgentHandler->>RuntimeFactory: create component (name, params)
RuntimeFactory-->>AgentHandler: Component instance
AgentHandler->>Component: GetInputForm()
Component-->>AgentHandler: schema or nil
end
AgentHandler-->>Client: input form schema
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/handler/agent_component.go (1)
87-114: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low valueDrop the unused
ctxanduserIDparameters.componentInputFormdoesn’t use them, and the onlyGetInputFormimplementation in the repo doesn’t need request or tenant state either.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/handler/agent_component.go` around lines 87 - 114, The componentInputForm helper in AgentHandler currently accepts ctx and userID but never uses them, so remove those unused parameters from the function signature and from any call sites to keep the API minimal. Update the componentInputForm method and any references to its signature around dsl.ExtractComponentInputForm, dsl.ExtractComponentName, and runtime.DefaultFactory usage so the code still compiles cleanly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/handler/agent_component.go`:
- Line 87: componentInputForm should guard against runtime.DefaultFactory()
being nil before calling it, just like DebugComponent does. Update the factory
lookup in AgentHandler.componentInputForm to check for a nil factory and return
a clean error/500 path instead of invoking runtime.DefaultFactory()(name,
params) directly, so the GET component input-form request cannot panic when the
runtime factory is uninitialized.
---
Nitpick comments:
In `@internal/handler/agent_component.go`:
- Around line 87-114: The componentInputForm helper in AgentHandler currently
accepts ctx and userID but never uses them, so remove those unused parameters
from the function signature and from any call sites to keep the API minimal.
Update the componentInputForm method and any references to its signature around
dsl.ExtractComponentInputForm, dsl.ExtractComponentName, and
runtime.DefaultFactory usage so the code still compiles cleanly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 2bd9f58a-5886-4d57-b137-30197043217f
📒 Files selected for processing (1)
internal/handler/agent_component.go
| // it instantiates the runtime component and calls its GetInputForm method. | ||
| // This mirrors Python's Canvas.get_component_input_form which invokes the | ||
| // component's own get_input_form when the static field is absent. | ||
| func (h *AgentHandler) componentInputForm(ctx context.Context, dslMap map[string]any, componentID, userID string) (map[string]any, error) { |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Missing nil check on runtime.DefaultFactory().
DebugComponent (Line 188-192) explicitly guards against runtime.DefaultFactory() returning nil before invoking it. componentInputForm calls runtime.DefaultFactory()(name, params) directly at Line 101 without the same guard — if the factory isn't initialized, this panics on a reachable request path (GET component input-form) instead of returning a clean 500 like its sibling handler does.
🐛 Proposed fix
params, _ := dsl.ExtractComponentParams(dslMap, componentID)
- comp, err := runtime.DefaultFactory()(name, params)
+ factory := runtime.DefaultFactory()
+ if factory == nil {
+ return nil, fmt.Errorf("%w: component factory not initialised", dsl.ErrMalformedDSL)
+ }
+ comp, err := factory(name, params)
if err != nil {
return nil, fmt.Errorf("%w: component factory: %v", dsl.ErrMalformedDSL, err)
}Also applies to: 101-104
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/handler/agent_component.go` at line 87, componentInputForm should
guard against runtime.DefaultFactory() being nil before calling it, just like
DebugComponent does. Update the factory lookup in
AgentHandler.componentInputForm to check for a nil factory and return a clean
error/500 path instead of invoking runtime.DefaultFactory()(name, params)
directly, so the GET component input-form request cannot panic when the runtime
factory is uninitialized.
|
LGTM |
Summary
This PR fixes two issues that prevented the Agent component's single-component debug/test run from working under the Go backend:
Dynamic input_form generation: Some components (e.g.
Agent) do not store a staticinput_formin the DSL. The Go handler now falls back to the runtime component'sGetInputForm()method, matching Python'sCanvas.get_component_input_formbehavior. This resolves the frontend 102 error:component has no input_form.Tenant ID injection for debug: Single-component debug runs use a fresh
CanvasStatethat previously lackedtenant_id.AgentComponent.Invokeresolves LLM credentials via the tenant tables, so the debug run failed withapi key is required. The handler now seedsstate.Sys["tenant_id"]with the authenticated user's ID, mirroring Python's@add_tenant_id_to_kwargsdecorator.Changes
internal/handler/agent_component.go:componentInputFormhelper that first reads the staticinput_formand, if missing, instantiates the component and callsGetInputForm().DebugComponent, setdebugState.Sys["tenant_id"] = user.IDbefore invoking the component.