Skip to content

API Reference parrot.integrations.msagentsdk.resume

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.integrations.msagentsdk.resume

View source

MSAgentSDK conversation-reference store and proactive-resume helper.

FEAT-264 / TASK-1674

When a tool raises :class:~parrot.auth.credentials.CredentialRequired during ParrotM365Agent._handle_message, the agent:

  1. Saves a :class:~parrot.human.suspended_store.SuspendedExecution record (keyed by nonce = interaction_id) so the original question can be replayed without user re-typing.
  2. Saves a :class:MsaConversationReference record (also keyed by nonce and by user_id) so the proactive-resume helper can route the reply back to the correct conversation.

On consent completion, two resume triggers call :func:proactive_resume:

  • OAuth/OBO — the Bot Framework Token Service sends a signin/verifyState or signin/tokenExchange invoke. The agent looks up the conversation reference by user_id (since the invoke carries no nonce) and calls :func:proactive_resume.
  • Static key — the OOB capture route (TASK-1677) calls :meth:ParrotM365Agent.resume_by_nonce passing the nonce extracted from the callback URL.

Proactive delivery uses the Microsoft 365 Agents SDK::

await adapter.continue_conversation(agent_app_id, continuation_activity, callback)

Where continuation_activity.conversation.id and continuation_activity.service_url are required fields (_validate_continuation_activity check in the SDK).

The MsaConversationRefStore falls back to an in-memory dict when no Redis client is supplied, which makes it usable in unit tests and local dev without a Redis dependency.

Class MsaConversationRefStore

Async store for :class:MsaConversationReference records.

Supports lookup by nonce (for static-key capture callback) and by user_id (for OAuth/OBO signin invokes where no nonce is available).

Falls back to an in-memory dict when redis=None (unit tests / local dev).

Parameter Type Default Description
redis Any None An async Redis client with setex / get / delete coroutine methods. Pass None for the in-memory fallback.

Method MsaConversationRefStore.save

Persist a conversation reference under both nonce and user_id keys.

save(ref: MsaConversationReference, ttl: int = _DEFAULT_TTL) -> None

Parameter Type Default Description
ref MsaConversationReference The :class:MsaConversationReference to persist.
ttl int _DEFAULT_TTL Time-to-live in seconds (default: 3600 / 1 hour).

Method MsaConversationRefStore.load_by_nonce

Load a conversation reference by nonce.

load_by_nonce(nonce: str) -> Optional[MsaConversationReference]

Parameter Type Default Description
nonce str The per-interaction nonce (uuid4().hex).

Returns: Optional[MsaConversationReference] — class:MsaConversationReference if found, None otherwise.

Method MsaConversationRefStore.load_by_user

Load a conversation reference by canonical user_id.

Used by OAuth/OBO resume triggers (signin/verifyState, signin/tokenExchange) where the nonce is not present in the incoming invoke activity.

load_by_user(user_id: str) -> Optional[MsaConversationReference]

Parameter Type Default Description
user_id str Canonical user identity.

Returns: Optional[MsaConversationReference] — class:MsaConversationReference if found, None otherwise.

Method MsaConversationRefStore.delete

Remove both keys for a conversation reference.

delete(ref: MsaConversationReference) -> None

Parameter Type Default Description
ref MsaConversationReference The :class:MsaConversationReference to remove.

Class MsaConversationReference

Minimal conversation reference for MSAgentSDK proactive resume.

Stored alongside the :class:~parrot.human.suspended_store.SuspendedExecution record so the resume helper can open a proactive turn to the correct conversation and channel.

Fields:

Field Type Default Description
nonce str Unique per-suspended-interaction ID (uuid4().hex). Used as the interaction_id in the companion :class:~parrot.human.suspended_store.SuspendedExecution record.
conversation_id str Bot Framework conversation ID (from activity.conversation.id). Required by the SDK's continue_conversation call.
service_url str Channel service URL (from activity.service_url). Required by the SDK's continue_conversation call.
user_id str Canonical user identity at the time of suspension.
channel_id str 'msteams' Bot Framework channel identifier (default: "msteams").
created_at datetime UTC timestamp of record creation.

Function proactive_resume

Re-run the suspended ask() and proactively deliver the response.

Confirmed proactive SDK API (FEAT-264 TASK-1674 — open question §8)::

await adapter.continue_conversation(
    agent_app_id,          # str — Microsoft App ID
    continuation_activity, # Activity with .conversation.id + .service_url
    callback,              # async (TurnContext) -> None
)

The continuation_activity must carry:

  • continuation_activity.conversation.id — the original conversation
  • continuation_activity.service_url — required by SDK validation

On credential failure during the re-run, a fallback error message is sent rather than raising (no card loop).

proactive_resume(adapter: Any, agent_app_id: str, conv_ref: MsaConversationReference, parrot_agent: Any, question: str, session_id: str, user_id: str, broker: Optional[Any] = None, on_sent: Optional[Callable[[Any], Awaitable[None]]] = None) -> None

Parameter Type Default Description
adapter Any The CloudAdapter instance from MSAgentSDKWrapper.
agent_app_id str Microsoft App ID (config.client_id).
conv_ref MsaConversationReference Stored :class:MsaConversationReference with conversation context for the proactive send.
parrot_agent Any The ai-parrot bot to call ask() on.
question str The original user question to replay (no re-typing required).
session_id str Agent session identifier (forwarded to ask()).
user_id str Canonical user identity (forwarded to ask()).
broker Optional[Any] None Optional :class:~parrot.auth.broker.CredentialBroker — passed as the broker seam kwargs to ask() so the re-run can resolve credentials.
on_sent Optional[Callable[[Any], Awaitable[None]]] None Optional async callback invoked with the TurnContext after the reply is sent. Used in tests to capture the context.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally