#Help how to send message in a programmable way
1 messages · Page 1 of 1 (latest)
@low cipher have you tried sendMessage from: https://docs.copilotkit.ai/reference/hooks/useCopilotChat#use-cases ?
Hi @low cipher !
You can give this a try!
import { useAgent } from "@copilotkit/react-core/v2"
const { agent } = useAgent()
const sendMessage = () => {
agent.addMessage()
agent.runAgent()
}
i tried with your code as follows,bu it seems failed,while i can see the request was send to the server ,and the server respond corresponding content。but the streamable content fron the server not been rendered in the CopilotChat. herer is my test code(sorry it's my first time using discord,i don't kow how to format my code in a right way):export default function AMapChat() {
const { data: session } = useSession();
const { agent } = useAgent({ agentId: "amap" });
const consumePrompt = useInitPromptStore((s) => s.consumePrompt);//get a initial prompt from zustand store
useEffect(() => {
const run = async () => {
const initial = consumePrompt();
if (initial) {
agent.addMessage({
id: crypto.randomUUID(),
role: "user",
content: initial,
});
await agent.runAgent();
}
};
void run();
}, [consumePrompt, agent]);
return (
<div
className="flex flex-col h-full w-full"
style={
{
"--copilot-kit-primary-color": "var(--color-primary)",
} as CopilotKitCSSProperties
}
>
<CopilotChat
threadId={`amap-${session?.user?.id}`}
agentId={"amap"}
/>
</div>
);
}
Thanks for the additional context, @low cipher! The team will get back to you soon.
thank you,i update beta.7 and then i found CopilotChat can be given the value and onChange paramters which resolved my problems