Skip to content

Commit db5bbda

Browse files
authored
fix: disable system message (CopilotKit#2313)
1 parent 6d060ac commit db5bbda

11 files changed

Lines changed: 52 additions & 7 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@copilotkit/react-core": patch
3+
"@copilotkit/react-ui": patch
4+
---
5+
6+
- fix: allow disabling of default cpk system message
7+
- chore: set up direct fastapi usage on coagents starter poetry demo

CopilotKit/packages/react-core/src/hooks/use-chat.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ export type UseChatOptions = {
159159
langGraphInterruptAction: LangGraphInterruptAction | null;
160160

161161
setLangGraphInterruptAction: LangGraphInterruptActionSetter;
162+
163+
disableSystemMessage?: boolean;
162164
};
163165

164166
export type UseChatHelpers = {
@@ -222,6 +224,7 @@ export function useChat(options: UseChatOptions): UseChatHelpers {
222224
setExtensions,
223225
langGraphInterruptAction,
224226
setLangGraphInterruptAction,
227+
disableSystemMessage = false,
225228
} = options;
226229
const runChatCompletionRef = useRef<(previousMessages: Message[]) => Promise<Message[]>>();
227230
const addErrorToast = useErrorToast();
@@ -321,9 +324,9 @@ export function useChat(options: UseChatOptions): UseChatHelpers {
321324

322325
setMessages([...previousMessages, ...newMessages]);
323326

324-
const systemMessage = makeSystemMessageCallback();
325-
326-
const messagesWithContext = [systemMessage, ...(initialMessages || []), ...previousMessages];
327+
const messagesWithContext = disableSystemMessage
328+
? [...(initialMessages || []), ...previousMessages]
329+
: [makeSystemMessageCallback(), ...(initialMessages || []), ...previousMessages];
327330

328331
// ----- Set mcpServers in properties -----
329332
// Create a copy of properties to avoid modifying the original object
@@ -871,6 +874,7 @@ export function useChat(options: UseChatOptions): UseChatHelpers {
871874
coagentStatesRef,
872875
agentSession,
873876
setAgentSession,
877+
disableSystemMessage,
874878
],
875879
);
876880

CopilotKit/packages/react-core/src/hooks/use-copilot-chat_internal.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ export interface UseCopilotChatOptions {
4141
* A function to generate the system message. Defaults to `defaultSystemMessage`.
4242
*/
4343
makeSystemMessage?: SystemMessageFunction;
44+
45+
/**
46+
* Disables inclusion of CopilotKit’s default system message. When true, no system message is sent (this also suppresses any custom message from <code>makeSystemMessage</code>).
47+
*/
48+
disableSystemMessage?: boolean;
4449
}
4550

4651
export interface MCPServerConfig {
@@ -390,6 +395,7 @@ export function useCopilotChat(options: UseCopilotChatOptions = {}): UseCopilotC
390395
setExtensions,
391396
langGraphInterruptAction,
392397
setLangGraphInterruptAction,
398+
disableSystemMessage: options.disableSystemMessage,
393399
});
394400

395401
const latestAppend = useUpdatedRef(append);

CopilotKit/packages/react-ui/src/components/chat/Chat.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ export interface CopilotChatProps {
225225
*/
226226
makeSystemMessage?: SystemMessageFunction;
227227

228+
/**
229+
* Disables inclusion of CopilotKit’s default system message. When true, no system message is sent (this also suppresses any custom message from <code>makeSystemMessage</code>).
230+
*/
231+
disableSystemMessage?: boolean;
232+
228233
/**
229234
* A custom assistant message component to use instead of the default.
230235
*/
@@ -384,6 +389,7 @@ export function CopilotChat({
384389
suggestions = "auto",
385390
onSubmitMessage,
386391
makeSystemMessage,
392+
disableSystemMessage,
387393
onInProgress,
388394
onStopGeneration,
389395
onReloadMessages,
@@ -584,6 +590,7 @@ export function CopilotChat({
584590
} = useCopilotChatLogic(
585591
suggestions,
586592
makeSystemMessage,
593+
disableSystemMessage,
587594
onInProgress,
588595
onSubmitMessage,
589596
onStopGeneration,
@@ -789,6 +796,7 @@ export function WrappedCopilotChat({
789796
export const useCopilotChatLogic = (
790797
chatSuggestions: ChatSuggestions,
791798
makeSystemMessage?: SystemMessageFunction,
799+
disableSystemMessage?: boolean,
792800
onInProgress?: (isLoading: boolean) => void,
793801
onSubmitMessage?: (messageContent: string) => Promise<void> | void,
794802
onStopGeneration?: OnStopGeneration,
@@ -809,6 +817,7 @@ export const useCopilotChatLogic = (
809817
isLoadingSuggestions,
810818
} = useCopilotChat({
811819
makeSystemMessage,
820+
disableSystemMessage,
812821
});
813822

814823
const generalContext = useCopilotContext();

docs/content/docs/reference/components/chat/CopilotChat.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ A function that takes in context string and instructions and returns
162162
instructions is not enough.
163163
</PropertyReference>
164164

165+
<PropertyReference name="disableSystemMessage" type="boolean" >
166+
Disables inclusion of CopilotKit’s default system message. When true, no system message is sent (this also suppresses any custom message from <code>makeSystemMessage</code>).
167+
</PropertyReference>
168+
165169
<PropertyReference name="AssistantMessage" type="React.ComponentType<AssistantMessageProps>" >
166170
A custom assistant message component to use instead of the default.
167171
</PropertyReference>

docs/content/docs/reference/components/chat/CopilotPopup.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ A function that takes in context string and instructions and returns
166166
instructions is not enough.
167167
</PropertyReference>
168168

169+
<PropertyReference name="disableSystemMessage" type="boolean" >
170+
Disables inclusion of CopilotKit’s default system message. When true, no system message is sent (this also suppresses any custom message from <code>makeSystemMessage</code>).
171+
</PropertyReference>
172+
169173
<PropertyReference name="AssistantMessage" type="React.ComponentType<AssistantMessageProps>" >
170174
A custom assistant message component to use instead of the default.
171175
</PropertyReference>

docs/content/docs/reference/components/chat/CopilotSidebar.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ A function that takes in context string and instructions and returns
170170
instructions is not enough.
171171
</PropertyReference>
172172

173+
<PropertyReference name="disableSystemMessage" type="boolean" >
174+
Disables inclusion of CopilotKit’s default system message. When true, no system message is sent (this also suppresses any custom message from <code>makeSystemMessage</code>).
175+
</PropertyReference>
176+
173177
<PropertyReference name="AssistantMessage" type="React.ComponentType<AssistantMessageProps>" >
174178
A custom assistant message component to use instead of the default.
175179
</PropertyReference>

docs/content/docs/reference/hooks/useCopilotChat.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,7 @@ Initial messages to populate the chat with.
102102
A function to generate the system message. Defaults to `defaultSystemMessage`.
103103
</PropertyReference>
104104

105+
<PropertyReference name="disableSystemMessage" type="boolean" >
106+
Disables inclusion of CopilotKit’s default system message. When true, no system message is sent (this also suppresses any custom message from <code>makeSystemMessage</code>).
107+
</PropertyReference>
108+

examples/coagents-starter/agent-py/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ __pycache__/
33
*.pyc
44
.env
55
.vercel
6+
7+
# LangGraph API
8+
.langgraph_api

examples/coagents-starter/agent-py/sample_agent/agent.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,9 @@ async def chat_node(state: AgentState, config: RunnableConfig) -> Command[Litera
113113

114114
# Conditionally use a checkpointer based on the environment
115115
# Check for multiple indicators that we're running in LangGraph dev/API mode
116-
is_langgraph_api = (
117-
os.environ.get("LANGGRAPH_API", "false").lower() == "true" or
118-
os.environ.get("LANGGRAPH_API_DIR") is not None
119-
)
116+
is_langgraph_api = os.environ.get("LANGGRAPH_API_DIR") is not None
117+
if os.environ.get("LANGGRAPH_API", None) is not None:
118+
is_langgraph_api = os.environ.get("LANGGRAPH_API", None).lower() == "true"
120119

121120
if is_langgraph_api:
122121
# When running in LangGraph API/dev, don't use a custom checkpointer

0 commit comments

Comments
 (0)