mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 20:03:05 +00:00
Support multiple messages in agent.prompt() and agentLoop
- agentLoop now accepts AgentMessage[] instead of single message - agent.prompt() accepts AgentMessage | AgentMessage[] - Emits message_start/end for each message in the array - AgentSession.prompt() builds array with hook message + user message - TUI now receives events for before_agent_start injected messages
This commit is contained in:
parent
575c875475
commit
41af99cccf
4 changed files with 48 additions and 36 deletions
|
|
@ -490,30 +490,36 @@ export class AgentSession {
|
|||
// Expand file-based slash commands if requested
|
||||
const expandedText = expandCommands ? expandSlashCommand(text, [...this._fileCommands]) : text;
|
||||
|
||||
// Build messages array (hook message if any, then user message)
|
||||
const messages: AgentMessage[] = [];
|
||||
|
||||
// Add user message
|
||||
const userContent: (TextContent | ImageContent)[] = [{ type: "text", text: expandedText }];
|
||||
if (options?.images) {
|
||||
userContent.push(...options.images);
|
||||
}
|
||||
messages.push({
|
||||
role: "user",
|
||||
content: userContent,
|
||||
timestamp: Date.now(),
|
||||
});
|
||||
|
||||
// Emit before_agent_start hook event
|
||||
if (this._hookRunner) {
|
||||
const result = await this._hookRunner.emitBeforeAgentStart(expandedText, options?.images);
|
||||
if (result?.message) {
|
||||
// Append hook message to agent state and session
|
||||
const hookMessage: HookMessage = {
|
||||
messages.push({
|
||||
role: "hookMessage",
|
||||
customType: result.message.customType,
|
||||
content: result.message.content,
|
||||
display: result.message.display,
|
||||
details: result.message.details,
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
this.agent.appendMessage(hookMessage);
|
||||
this.sessionManager.appendCustomMessageEntry(
|
||||
result.message.customType,
|
||||
result.message.content,
|
||||
result.message.display,
|
||||
result.message.details,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await this.agent.prompt(expandedText, options?.images);
|
||||
await this.agent.prompt(messages);
|
||||
await this.waitForRetry();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue