microsoft/semantic-kernel · error · AgentInvokeException
No token received.
Error message
No token received.
What it means
An AgentInvokeException from the fallback (no bot_secret) branch: GET to token_endpoint returned 200 but the JSON body lacked a 'token' field. Functionally the same malformed-response condition as the bot_secret branch, just reached via the alternate token_endpoint path.
Source
Thrown at python/samples/demos/copilot_studio_agent/src/direct_line_agent.py:75
headers = {"Authorization": f"Bearer {self.bot_secret}"}
async with self.session.post(url, headers=headers) as resp:
if resp.status == 200:
data = await resp.json()
self.directline_token = data.get("token")
if not self.directline_token:
logger.error("Token generation response missing token: %s", data)
raise AgentInvokeException("No token received from token generation.")
else:
logger.error("Token generation endpoint error status: %s", resp.status)
raise AgentInvokeException("Failed to generate token using bot_secret.")
else:
async with self.session.get(self.token_endpoint) as resp:
if resp.status == 200:
data = await resp.json()
self.directline_token = data.get("token")
if not self.directline_token:
logger.error("Token endpoint returned no token: %s", data)
raise AgentInvokeException("No token received.")
else:
logger.error("Token endpoint error status: %s", resp.status)
raise AgentInvokeException("Failed to fetch token from token endpoint.")
except Exception as ex:
logger.exception("Exception fetching token: %s", ex)
raise AgentInvokeException("Exception occurred while fetching token.") from ex
@trace_agent_get_response
@override
async def get_response(
self,
history: ChatHistory,
arguments: dict[str, Any] | None = None,
**kwargs: Any,
) -> ChatMessageContent:
"""
Get a response from the DirectLine Bot.
"""View on GitHub (pinned to c028a0c7dc)
Solutions
- Inspect the logged body (logger.error) to find the real token key.
- Confirm token_endpoint is the actual token-issuing URL, not a generic service base URL.
- Switch to the bot_secret flow if the token_endpoint path is unsupported for your setup.
Example fix
// before
self.directline_token = data.get("token") # body had different key
// after
logger.error("Token endpoint body: %s", data)
self.directline_token = data.get("token") or data.get("access_token") Defensive patterns
Strategy: try-catch
Try / catch
try:
await fetch_token()
except AgentInvokeException as e:
if "No token received" in str(e):
logger.error("Token endpoint 200 without token; inspect body schema.")
raise Prevention
- Confirm token_endpoint returns the canonical {"token": ...} shape.
- Prefer the bot_secret flow for deterministic auth.
When it happens
Trigger: self.bot_secret is unset, so the agent GETs self.token_endpoint; it returns 200 with a body that does not contain 'token'.
Common situations: token_endpoint points at an endpoint returning a different schema; a gateway returns a health-check 200 without token data; the endpoint URL is correct but the service isn't a token issuer.
Related errors
- No token received from token generation.
- Failed to generate token using bot_secret.
- Failed to fetch token from token endpoint.
- Exception occurred while fetching token.
- Failed to start conversation.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/ee3bc648aa2f0549.
Report an issue: GitHub.