Skip to content

Commit d1e60cf

Browse files
committed
add enable streaming option for a2a client
1 parent 5b3c998 commit d1e60cf

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

agent/a2aagent/a2a_agent.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type A2AAgent struct {
4646
streamingRespHandler StreamingRespHandler // Handler for streaming responses
4747
transferStateKey []string // Keys in session state to transfer to the A2A agent message by metadata
4848
userIDHeader string // HTTP header name to send UserID to A2A server
49+
enableStreaming *bool // Explicitly set streaming mode; nil means use agent card capability
4950

5051
a2aClient *client.A2AClient
5152
}
@@ -161,7 +162,12 @@ func (r *A2AAgent) Run(ctx context.Context, invocation *agent.Invocation) (<-cha
161162

162163
// shouldUseStreaming determines whether to use streaming protocol
163164
func (r *A2AAgent) shouldUseStreaming() bool {
164-
// Check if agent card supports streaming
165+
// If explicitly set via option, use that value
166+
if r.enableStreaming != nil {
167+
return *r.enableStreaming
168+
}
169+
170+
// Otherwise check if agent card supports streaming
165171
if r.agentCard != nil && r.agentCard.Capabilities.Streaming != nil {
166172
return *r.agentCard.Capabilities.Streaming
167173
}

agent/a2aagent/a2a_agent_option.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,12 @@ func WithUserIDHeader(header string) Option {
105105
}
106106
}
107107
}
108+
109+
// WithEnableStreaming explicitly controls whether to use streaming protocol.
110+
// If not set (nil), the agent will use the streaming capability from the agent card.
111+
// This option overrides the agent card's capability setting.
112+
func WithEnableStreaming(enable bool) Option {
113+
return func(a *A2AAgent) {
114+
a.enableStreaming = &enable
115+
}
116+
}

0 commit comments

Comments
 (0)