[Refactor]: Eliminate wrappedSession and decouple workflow node prompt injection from Session
- Dominant language
- Go
- Stars
- 8.8k
- Forks
- 1k
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 88
Description
### Problem Description
In `agent/llmagent/llm_agent_wrapper.go:642-660`, `single_turn` workflow nodes inject transient node inputs into the LLM prompt by wrapping the underlying session in synthetic `wrappedSession` and `wrappedEvents` structs (`PrepareLLMAgentInput`).
This has significant architectural drawbacks (noted by maintainers in `TODO` at `llm_agent_wrapper.go:642`):
1. **Session Pollution**: Wrapping the session pollutes the `session.Session` abstraction: any tool, plugin, callback, or telemetry hook inspecting `ctx.Session()` during execution sees synthetic phantom events that do not exist in persistent storage.
2. **Unnecessary Coupling**: Faking a session event just to feed a prompt to the LLM couples workflow graph node orchestration to session state manipulation.
3. **Index Drift Risk**: `wrappedEvents.At(i)` relies on manual index offset math (`insertAt`), which risks index misalignment during multi-round tool executions.
### Proposed Solution
As outlined in the codebase `TODO`:
1. Eliminate `wrappedSession`, `wrappedEvents`, and `PrepareLLMAgentInput` from `agent/llmagent/llm_agent_wrapper.go`.
2. Rely directly on `InvocationContext.UserContent()` (which already carries the rendered `nodeInput`).
3. Update `internal/llminternal/contents_processor.go` to directly read `ctx.UserContent()` and prepend it to `LLMRequest.Contents` for `single_turn` agents.
4. Keep the session history pure, properly decoupling workflow node inputs from session state.
Contributor guide
Research direction
Read the TODO and `PrepareLLMAgentInput` in `agent/llmagent/llm_agent_wrapper.go:642-660`, then trace `InvocationContext.UserContent()` into `internal/llminternal/contents_processor.go`. The work is done when the wrapped session/event types and helper are removed, single-turn prompt input is prepended from `UserContent()`, and session history remains free of synthetic events.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- ai, backend-api-design
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100