-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Agent streaming #1309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Agent streaming #1309
Conversation
🦋 Changeset detectedLatest commit: 0d06078 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Greptile OverviewGreptile SummaryAdded streaming support to the V3 non-CUA agent by implementing a new Key changes:
The refactoring improves code maintainability by eliminating duplication between streaming and non-streaming paths. Confidence Score: 5/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant User
participant V3
participant V3AgentHandler
participant LLMClient
participant AI_SDK
User->>V3: agent.stream(instruction)
V3->>V3: check experimental flag
V3->>V3AgentHandler: new V3AgentHandler(...)
V3->>V3AgentHandler: stream(instruction)
V3AgentHandler->>V3AgentHandler: prepareAgent(instruction)
V3AgentHandler->>V3AgentHandler: create AgentState
V3AgentHandler->>V3AgentHandler: create Promise for result
V3AgentHandler->>LLMClient: streamText(config)
LLMClient->>AI_SDK: streamText with tools
AI_SDK-->>V3AgentHandler: StreamTextResult
V3AgentHandler->>V3AgentHandler: attach result Promise
V3AgentHandler-->>V3: AgentStreamResult
V3-->>User: AgentStreamResult
Note over User,AI_SDK: Streaming phase begins
loop For each text delta
AI_SDK-->>User: textStream delta
end
loop For each step
AI_SDK->>V3AgentHandler: onStepFinish(event)
V3AgentHandler->>V3AgentHandler: createStepHandler processes
V3AgentHandler->>V3AgentHandler: update AgentState
V3AgentHandler->>V3AgentHandler: check for "close" tool
V3AgentHandler->>V3AgentHandler: map tool results to actions
end
AI_SDK->>V3AgentHandler: onFinish(event)
V3AgentHandler->>V3AgentHandler: consolidateMetricsAndResult()
V3AgentHandler->>V3: updateMetrics()
V3AgentHandler->>V3AgentHandler: resolve result Promise
User->>User: await result.result
V3AgentHandler-->>User: AgentResult
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 files reviewed, 1 comment
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
why
We wanted to add streaming support to the non-CUA agent in V3
what changed
Added
streammethod toV3AgentHandler:streamTextinstead ofgenerateTextAgentStreamResult, which extendsStreamTextResultwith an addedresult: Promise<AgentResult>propertyonFinishcallback to resolve the result promise with metrics and final stateConsolidated duplicate logic:
prepareAgent()helper to build context (system prompt, tools, wrapped model) for bothexecuteandstreamcreateStepHandler()to generate theonStepFinishcallback used by both methodsconsolidateMetricsAndResult()to handle metrics updates andAgentResultconstructionhandleStop()helper to check for "close" tool calls before falling back to step count limitMoved types to public agent types:
AgentContextandAgentStateinterfaces frompackages/core/lib/v3/types/public/agent.tsAgentStreamResulttype that combinesStreamTextResult<ToolSet, never>withresult: Promise<AgentResult>Updated
V3.agent()return type:streammethod alongsideexecutefor non-CUA agentsexecute(no streaming support)notes : context handling will likely be moved to prepareStep callback in the very near future, currently we have to maintain a state of the messages which is not ideal. prepareStep should eliminate the need for this