Skip to content
Merged
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
7 changes: 4 additions & 3 deletions cmd/root/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,17 +361,18 @@ func runWithoutTUI(ctx context.Context, agentFilename string, rt runtime.Runtime
llmIsTyping := false
var lastConfirmedToolCallID string
for event := range rt.RunStream(loopCtx, sess) {
if event.GetAgentName() != "" && (firstLoop || lastAgent != event.GetAgentName()) {
agentName := event.GetAgentName()
if agentName != "" && (firstLoop || lastAgent != agentName) {
if !firstLoop {
if llmIsTyping {
fmt.Println()
llmIsTyping = false
}
fmt.Println()
}
printAgentName(event.GetAgentName())
printAgentName(agentName)
firstLoop = false
lastAgent = event.GetAgentName()
lastAgent = agentName
}
switch e := event.(type) {
case *runtime.AgentChoiceEvent:
Expand Down
86 changes: 20 additions & 66 deletions pkg/runtime/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
)

type Event interface {
isEvent()
GetAgentName() string
}

Expand All @@ -23,19 +22,15 @@ type UserMessageEvent struct {
Message string `json:"message"`
}

func (e *UserMessageEvent) GetAgentName() string { return "" }

func UserMessage(message string) Event {
return &UserMessageEvent{
Type: "user_message",
Message: message,
}
}

func (e *UserMessageEvent) GetAgentName() string {
return ""
}

func (e *UserMessageEvent) isEvent() {}

// PartialToolCallEvent is sent when a tool call is first received (partial/complete)
type PartialToolCallEvent struct {
Type string `json:"type"`
Expand All @@ -53,8 +48,6 @@ func PartialToolCall(toolCall tools.ToolCall, toolDefinition tools.Tool, agentNa
}
}

func (e *PartialToolCallEvent) isEvent() {}

// ToolCallEvent is sent when a tool call is received
type ToolCallEvent struct {
Type string `json:"type"`
Expand All @@ -71,8 +64,6 @@ func ToolCall(toolCall tools.ToolCall, toolDefinition tools.Tool, agentName stri
}
}

func (e *ToolCallEvent) isEvent() {}

type ToolCallConfirmationEvent struct {
Type string `json:"type"`
ToolCall tools.ToolCall `json:"tool_call"`
Expand All @@ -88,7 +79,6 @@ func ToolCallConfirmation(toolCall tools.ToolCall, toolDefinition tools.Tool, ag
AgentContext: AgentContext{AgentName: agentName},
}
}
func (e *ToolCallConfirmationEvent) isEvent() {}

type ToolCallResponseEvent struct {
Type string `json:"type"`
Expand All @@ -105,7 +95,6 @@ func ToolCallResponse(toolCall tools.ToolCall, response, agentName string) Event
AgentContext: AgentContext{AgentName: agentName},
}
}
func (e *ToolCallResponseEvent) isEvent() {}

type StreamStartedEvent struct {
Type string `json:"type"`
Expand All @@ -121,41 +110,33 @@ func StreamStarted(sessionID, agentName string) Event {
}
}

func (e *StreamStartedEvent) GetAgentName() string {
return e.AgentName
}

func (e *StreamStartedEvent) isEvent() {}

type AgentChoiceEvent struct {
Type string `json:"type"`
Content string `json:"content"`
AgentContext
}

func AgentChoice(agentName, content string) Event { //nolint:gocritic
func AgentChoice(agentName, content string) Event {
return &AgentChoiceEvent{
Type: "agent_choice",
Content: content,
AgentContext: AgentContext{AgentName: agentName},
}
}
func (e *AgentChoiceEvent) isEvent() {}

type AgentChoiceReasoningEvent struct {
Type string `json:"type"`
Content string `json:"content"`
AgentContext
}

func AgentChoiceReasoning(agentName, content string) Event { //nolint:gocritic
func AgentChoiceReasoning(agentName, content string) Event {
return &AgentChoiceReasoningEvent{
Type: "agent_choice_reasoning",
Content: content,
AgentContext: AgentContext{AgentName: agentName},
}
}
func (e *AgentChoiceReasoningEvent) isEvent() {}

type ErrorEvent struct {
Type string `json:"type"`
Expand All @@ -169,21 +150,20 @@ func Error(msg string) Event {
Error: msg,
}
}
func (e *ErrorEvent) isEvent() {}

type ShellOutputEvent struct {
Type string `json:"type"`
Output string `json:"error"`
}

func (e *ShellOutputEvent) GetAgentName() string { return "" }

func ShellOutput(output string) Event {
return &ShellOutputEvent{
Type: "shell",
Output: output,
}
}
func (e *ShellOutputEvent) isEvent() {}
func (e *ShellOutputEvent) GetAgentName() string { return "" }

type TokenUsageEvent struct {
Type string `json:"type"`
Expand Down Expand Up @@ -211,7 +191,6 @@ func TokenUsage(inputTokens, outputTokens, contextLength, contextLimit int, cost
},
}
}
func (e *TokenUsageEvent) isEvent() {}

type SessionTitleEvent struct {
Type string `json:"type"`
Expand All @@ -222,15 +201,12 @@ type SessionTitleEvent struct {

func SessionTitle(sessionID, title, agentName string) Event {
return &SessionTitleEvent{
Type: "session_title",
SessionID: sessionID,
Title: title,
AgentContext: AgentContext{
AgentName: agentName,
},
Type: "session_title",
SessionID: sessionID,
Title: title,
AgentContext: AgentContext{AgentName: agentName},
}
}
func (e *SessionTitleEvent) isEvent() {}

type SessionSummaryEvent struct {
Type string `json:"type"`
Expand All @@ -241,15 +217,12 @@ type SessionSummaryEvent struct {

func SessionSummary(sessionID, summary, agentName string) Event {
return &SessionSummaryEvent{
Type: "session_summary",
SessionID: sessionID,
Summary: summary,
AgentContext: AgentContext{
AgentName: agentName,
},
Type: "session_summary",
SessionID: sessionID,
Summary: summary,
AgentContext: AgentContext{AgentName: agentName},
}
}
func (e *SessionSummaryEvent) isEvent() {}

type SessionCompactionEvent struct {
Type string `json:"type"`
Expand All @@ -260,15 +233,12 @@ type SessionCompactionEvent struct {

func SessionCompaction(sessionID, status, agentName string) Event {
return &SessionCompactionEvent{
Type: "session_compaction",
SessionID: sessionID,
Status: status,
AgentContext: AgentContext{
AgentName: agentName,
},
Type: "session_compaction",
SessionID: sessionID,
Status: status,
AgentContext: AgentContext{AgentName: agentName},
}
}
func (e *SessionCompactionEvent) isEvent() {}

type StreamStoppedEvent struct {
Type string `json:"type"`
Expand All @@ -284,12 +254,6 @@ func StreamStopped(sessionID, agentName string) Event {
}
}

func (e *StreamStoppedEvent) GetAgentName() string {
return e.AgentName
}

func (e *StreamStoppedEvent) isEvent() {}

type AuthorizationRequiredEvent struct {
Type string `json:"type"`
ServerURL string `json:"server_url"`
Expand All @@ -298,6 +262,8 @@ type AuthorizationRequiredEvent struct {
AgentContext
}

func (e *AuthorizationRequiredEvent) GetAgentName() string { return "" }

func AuthorizationRequired(serverURL, serverType, confirmation, agentName string) Event {
return &AuthorizationRequiredEvent{
Type: "authorization_required",
Expand All @@ -308,12 +274,6 @@ func AuthorizationRequired(serverURL, serverType, confirmation, agentName string
}
}

func (e *AuthorizationRequiredEvent) isEvent() {}

func (e *AuthorizationRequiredEvent) GetAgentName() string {
return ""
}

type MaxIterationsReachedEvent struct {
Type string `json:"type"`
MaxIterations int `json:"max_iterations"`
Expand All @@ -326,9 +286,3 @@ func MaxIterationsReached(maxIterations int) Event {
MaxIterations: maxIterations,
}
}

func (e *MaxIterationsReachedEvent) isEvent() {}

func (e *MaxIterationsReachedEvent) GetAgentName() string {
return e.AgentName
}
Loading