Skip to content
Open
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 pkg/a2a/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func runDockerAgent(ctx agent.InvocationContext, t *team.Team, agentName string,
session.WithMaxConsecutiveToolCalls(a.MaxConsecutiveToolCalls()),
session.WithMaxOldToolCallTokens(a.MaxOldToolCallTokens()),
session.WithToolsApproved(true),
session.WithNonInteractive(true),
)

// Create runtime
Expand Down
1 change: 1 addition & 0 deletions pkg/evaluation/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func SessionFromEvents(events []map[string]any, title string, questions []string
sess := session.New(
session.WithTitle(title),
session.WithToolsApproved(true),
session.WithNonInteractive(true),
)

// Add user questions as initial messages.
Expand Down
1 change: 1 addition & 0 deletions pkg/mcp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func CreateToolHandler(t *team.Team, agentName string) func(context.Context, *mc
session.WithMaxOldToolCallTokens(ag.MaxOldToolCallTokens()),
session.WithUserMessage(input.Message),
session.WithToolsApproved(true),
session.WithNonInteractive(true),
)

rt, err := runtime.New(t,
Expand Down
18 changes: 18 additions & 0 deletions pkg/runtime/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,24 @@ func (r *LocalRuntime) RunStream(ctx context.Context, sess *session.Session) <-c
r.executeNotificationHooks(ctx, a, sess.ID, "warning", maxIterMsg)
r.executeOnUserInputHooks(ctx, sess.ID, "max iterations reached")

// In non-interactive mode (e.g. MCP server), auto-stop instead of
// blocking forever waiting for user input.
if sess.NonInteractive {
slog.Debug("Auto-stopping after max iterations (non-interactive)", "agent", a.Name())

assistantMessage := chat.Message{
Role: chat.MessageRoleAssistant,
Content: fmt.Sprintf(
"Execution stopped after reaching the configured max_iterations limit (%d).",
runtimeMaxIterations,
),
CreatedAt: time.Now().Format(time.RFC3339),
}

addAgentMessage(sess, a, &assistantMessage, events)
return
}

// Wait for user decision (resume / reject)
select {
case req := <-r.resumeChan:
Expand Down
12 changes: 12 additions & 0 deletions pkg/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ type Session struct {
// ToolsApproved is a flag to indicate if the tools have been approved
ToolsApproved bool `json:"tools_approved"`

// NonInteractive indicates the session is running in a non-interactive context
// (e.g. MCP server, A2A adapter, evaluation framework) where there is no user
// to provide input. This is distinct from ToolsApproved which can also be set
// in interactive TUI sessions when a user approves all tools.
NonInteractive bool `json:"non_interactive,omitempty"`

// HideToolResults is a flag to indicate if tool results should be hidden
HideToolResults bool `json:"hide_tool_results"`

Expand Down Expand Up @@ -476,6 +482,12 @@ func WithToolsApproved(toolsApproved bool) Opt {
}
}

func WithNonInteractive(nonInteractive bool) Opt {
return func(s *Session) {
s.NonInteractive = nonInteractive
}
}

func WithHideToolResults(hideToolResults bool) Opt {
return func(s *Session) {
s.HideToolResults = hideToolResults
Expand Down