Skip to content

Commit eb986bd

Browse files
CopilotCopilot
andcommitted
fix: resolve pyright 'possibly unbound' errors in A2AAgent non-streaming path (microsoft#4754)
Initialize active_session and session_context before the conditional context_providers block so pyright can verify they are always bound. Add explicit None check for session_context in the after-providers guard. Co-authored-by: Copilot <[email protected]>
1 parent a8f7796 commit eb986bd

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

  • python/packages/a2a/agent_framework_a2a

‎python/packages/a2a/agent_framework_a2a/_agent.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ def run( # pyright: ignore[reportIncompatibleMethodOverride]
291291
if not stream:
292292

293293
async def _run_non_streaming() -> AgentResponse[Any]:
294+
active_session: AgentSession | None = None
295+
session_context: SessionContext | None = None
294296
if self.context_providers:
295297
active_session, session_context = await self._run_before_providers(
296298
session=session,
@@ -309,7 +311,7 @@ async def _run_non_streaming() -> AgentResponse[Any]:
309311
finalizer=AgentResponse.from_updates,
310312
)
311313
result = await response_stream.get_final_response()
312-
if self.context_providers:
314+
if self.context_providers and session_context is not None:
313315
session_context._response = result # type: ignore[assignment] # pyright: ignore[reportPrivateUsage]
314316
await self._run_after_providers(session=active_session, context=session_context)
315317
return result

0 commit comments

Comments
 (0)