Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/root/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ func createUserMessageWithAttachment(agentFilename, userContent, attachmentPath
Message: chat.Message{
Role: chat.MessageRoleUser,
MultiContent: multiContent,
CreatedAt: time.Now().Format(time.RFC3339),
},
}
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/chat/chat.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package chat

import "github.com/docker/cagent/pkg/tools"
import (
"github.com/docker/cagent/pkg/tools"
)

type MessageRole string

Expand Down Expand Up @@ -56,6 +58,9 @@ type Message struct {

// For Role=tool prompts this should be set to the ID given in the assistant's prior request to call a tool.
ToolCallID string `json:"tool_call_id,omitempty"`

// CreatedAt is the time the message was created
CreatedAt string `json:"created_at,omitempty"`
}

type MessagePart struct {
Expand Down
6 changes: 6 additions & 0 deletions pkg/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"log/slog"
"strings"
"time"

"github.com/docker/cagent/pkg/agent"
"github.com/docker/cagent/pkg/chat"
Expand Down Expand Up @@ -223,6 +224,7 @@ func (r *Runtime) RunStream(ctx context.Context, sess *session.Session) <-chan E
Role: chat.MessageRoleAssistant,
Content: content,
ToolCalls: calls,
CreatedAt: time.Now().Format(time.RFC3339),
}

sess.AddMessage(session.NewAgentMessage(a, &assistantMessage))
Expand Down Expand Up @@ -544,6 +546,7 @@ func (r *Runtime) runTool(ctx context.Context, tool tools.Tool, toolCall tools.T
Role: chat.MessageRoleTool,
Content: res.Output,
ToolCallID: toolCall.ID,
CreatedAt: time.Now().Format(time.RFC3339),
}
sess.AddMessage(session.NewAgentMessage(a, &toolResponseMsg))
}
Expand Down Expand Up @@ -584,6 +587,7 @@ func (r *Runtime) runAgentTool(ctx context.Context, handler ToolHandler, sess *s
Role: chat.MessageRoleTool,
Content: output,
ToolCallID: toolCall.ID,
CreatedAt: time.Now().Format(time.RFC3339),
}
sess.AddMessage(session.NewAgentMessage(a, &toolResponseMsg))
}
Expand All @@ -599,6 +603,7 @@ func (r *Runtime) addToolRejectedResponse(sess *session.Session, toolCall tools.
Role: chat.MessageRoleTool,
Content: result,
ToolCallID: toolCall.ID,
CreatedAt: time.Now().Format(time.RFC3339),
}
sess.AddMessage(session.NewAgentMessage(a, &toolResponseMsg))
}
Expand All @@ -614,6 +619,7 @@ func (r *Runtime) addToolCancelledResponse(sess *session.Session, toolCall tools
Role: chat.MessageRoleTool,
Content: result,
ToolCallID: toolCall.ID,
CreatedAt: time.Now().Format(time.RFC3339),
}
sess.AddMessage(session.NewAgentMessage(a, &toolResponseMsg))
}
Expand Down
30 changes: 18 additions & 12 deletions pkg/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ func UserMessage(agentFilename, content string) *Message {
AgentFilename: agentFilename,
AgentName: "",
Message: chat.Message{
Role: chat.MessageRoleUser,
Content: content,
Role: chat.MessageRoleUser,
Content: content,
CreatedAt: time.Now().Format(time.RFC3339),
},
}
}
Expand All @@ -93,8 +94,9 @@ func SystemMessage(content string) *Message {
AgentFilename: "",
AgentName: "",
Message: chat.Message{
Role: chat.MessageRoleSystem,
Content: content,
Role: chat.MessageRoleSystem,
Content: content,
CreatedAt: time.Now().Format(time.RFC3339),
},
}
}
Expand Down Expand Up @@ -199,8 +201,9 @@ func (s *Session) GetMessages(a *agent.Agent) []chat.Message {
}

messages = append(messages, chat.Message{
Role: "system",
Content: "You are a multi-agent system, make sure to answer the user query in the most helpful way possible. You have access to these sub-agents:\n" + subAgentsStr + "\nIMPORTANT: You can ONLY transfer tasks to the agents listed above using their ID. The valid agent IDs are: " + strings.Join(validAgentIDs, ", ") + ". You MUST NOT attempt to transfer to any other agent IDs - doing so will cause system errors.\n\nIf you are the best to answer the question according to your description, you can answer it.\n\nIf another agent is better for answering the question according to its description, call `transfer_task` function to transfer the question to that agent using the agent's ID. When transferring, do not generate any text other than the function call.\n\n",
Role: "system",
Content: "You are a multi-agent system, make sure to answer the user query in the most helpful way possible. You have access to these sub-agents:\n" + subAgentsStr + "\nIMPORTANT: You can ONLY transfer tasks to the agents listed above using their ID. The valid agent IDs are: " + strings.Join(validAgentIDs, ", ") + ". You MUST NOT attempt to transfer to any other agent IDs - doing so will cause system errors.\n\nIf you are the best to answer the question according to your description, you can answer it.\n\nIf another agent is better for answering the question according to its description, call `transfer_task` function to transfer the question to that agent using the agent's ID. When transferring, do not generate any text other than the function call.\n\n",
CreatedAt: time.Now().Format(time.RFC3339),
})
}

Expand All @@ -210,15 +213,17 @@ func (s *Session) GetMessages(a *agent.Agent) []chat.Message {
}

messages = append(messages, chat.Message{
Role: chat.MessageRoleSystem,
Content: a.Instruction() + "\n\n" + date,
Role: chat.MessageRoleSystem,
Content: a.Instruction() + "\n\n" + date,
CreatedAt: time.Now().Format(time.RFC3339),
})

for _, tool := range a.ToolSets() {
if tool.Instructions() != "" {
messages = append(messages, chat.Message{
Role: chat.MessageRoleSystem,
Content: tool.Instructions(),
Role: chat.MessageRoleSystem,
Content: tool.Instructions(),
CreatedAt: time.Now().Format(time.RFC3339),
})
}
}
Expand All @@ -233,8 +238,9 @@ func (s *Session) GetMessages(a *agent.Agent) []chat.Message {

if lastSummaryIndex != -1 {
messages = append(messages, chat.Message{
Role: chat.MessageRoleSystem,
Content: "Session Summary: " + s.Messages[lastSummaryIndex].Summary,
Role: chat.MessageRoleSystem,
Content: "Session Summary: " + s.Messages[lastSummaryIndex].Summary,
CreatedAt: time.Now().Format(time.RFC3339),
})
}

Expand Down
Loading