I am using a LangGraph dev server locally for the agent. The agent is using gemini-2.5-flash. On the frontend, I am trying to use CopilotChat for the chat interface. Whenever the AI sends a message longer than a few sentences, the message gets truncated. It only shows a small portion of the message. Is this a known error? How can I fix this?
#LangGraph w/ Gemini Messages are Truncated
1 messages · Page 1 of 1 (latest)
This solution has been AI generated
This is a known behavior we’ve seen when using LangGraph agents with Gemini and CopilotChat. It usually comes from a truncation helper in the agent code or a UI CSS clamp, not from CopilotChat’s streaming itself.
Why this happens
- Agent-side truncation: Many example agents use a
pretty_repr/similar helper that slices long texts (often ~1500 chars). This makes long replies appear cut off even though the backend streamed more. - UI visual truncation: CopilotChat message bubbles may inherit CSS like
truncate/line-clampthat visually clip long content. - Provider constraints: Gemini safety/token settings can also shorten texts.
How to fix
- Increase/disable agent-side truncation
- In your LangGraph agent utilities (e.g.,
examples/langgraph-tutorial-customer-support/agent-py/tutorial_customer_support/utilities.py), raise the limit:
# before
def pretty_repr(x, max_chars=1500):
s = repr(x)
return (s[:max_chars] + "…") if len(s) > max_chars else s
# after (larger cap or remove truncation)
def pretty_repr(x, max_chars=5000):
s = repr(x)
return (s[:max_chars] + "…") if len(s) > max_chars else s
- Remove UI clamping
- Inspect your chat message component for classes like
truncate,line-clamp-*,overflow-hidden, or fixedmax-h. Override them, for example:
.copilotchat-message {
white-space: pre-wrap;
overflow: visible;
}
- Verify Gemini settings
- Ensure your Gemini configuration isn’t enforcing short outputs via safety or token limits. Increase max tokens if applicable.
Validate the fix
- Enable backend logging (server stdout) to confirm the full assistant text is generated and streamed. If logs show full text but UI shows partial, it’s UI truncation. If logs are truncated, adjust the agent utility.
Sources:
- LangGraph Troubleshooting – Common Issues
- LangGraph Tutorial Agent Utilities
Was this helpful?
If this solution worked for you, please click on the appropriate option below to help us improve:
Thank you for confirming that your issue has been resolved! ✅
Hey! Just checking in - did that answer your question?