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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,20 @@ The `is_async` field reported in the `tengu_agent_tool_selected` event and the a

For best results, use models with strong tool/function calling support.

### Agent step limits

Custom agents can define `maxSteps` as a positive integer to cap how many tool-use steps a sub-agent may execute. When the limit is reached, OpenClaude stops additional tool calls and asks the sub-agent for a concise final summary covering completed work, findings, remaining tasks, and whether another run is needed. Omitting `maxSteps`, or setting it to an invalid value such as `0` or malformed input, preserves the default unlimited behavior.

```markdown
---
name: bounded-researcher
description: Use for focused research with bounded tool use
maxSteps: 8
---

You are a focused research agent.
```

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
## Agent Routing

OpenClaude can route different agents to different models through settings-based routing. This is useful for cost optimization or splitting work by model strength.
Expand Down
6 changes: 3 additions & 3 deletions src/components/ContextVisualization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ function CollapseStatus() {
return null;
}

// Order for displaying source groups: Project > User > Managed > Plugin > Built-in
const SOURCE_DISPLAY_ORDER = ['Project', 'User', 'Managed', 'Plugin', 'Built-in'];
// Order for displaying source groups: Project > User > Managed > Plugin > SDK > Built-in
const SOURCE_DISPLAY_ORDER = ['Project', 'User', 'Managed', 'Plugin', 'SDK', 'Built-in'];

/** Group items by source type for display, sorted by tokens descending within each group */
function groupBySource<T extends {
source: SettingSource | 'plugin' | 'built-in';
source: SettingSource | 'plugin' | 'sdk' | 'built-in';
tokens: number;
}>(items: T[]): Map<string, T[]> {
const groups = new Map<string, T[]>();
Expand Down
2 changes: 1 addition & 1 deletion src/components/agents/AgentsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Dialog } from '../design-system/Dialog.js';
import { Divider } from '../design-system/Divider.js';
import { getAgentSourceDisplayName } from './utils.js';
type Props = {
source: SettingSource | 'all' | 'built-in' | 'plugin';
source: SettingSource | 'all' | 'built-in' | 'plugin' | 'sdk';
agents: ResolvedAgent[];
onBack: () => void;
onSelect: (agent: AgentDefinition) => void;
Expand Down
115 changes: 115 additions & 0 deletions src/components/agents/AgentsMenu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,118 @@ test('omits set-active action when no session setter is available', async () =>
stdout.end()
}
})

test('shows SDK agents in all view without file edit actions', async () => {
const AgentsMenu = await importAgentsMenu()
const reviewer = createAgent('reviewer')
const sdkHelper = createAgent('sdk-helper', 'sdk')
const initialState = {
...getDefaultAppState(),
agentDefinitions: {
activeAgents: [reviewer, sdkHelper],
allAgents: [reviewer, sdkHelper],
},
}
const listStreams = createTestStreams()
const listRoot = await createRoot({
stdout: listStreams.stdout as unknown as NodeJS.WriteStream,
stdin: listStreams.stdin as unknown as NodeJS.ReadStream,
patchConsole: false,
})

listRoot.render(
<AppStateProvider initialState={initialState}>
<AgentsMenu
tools={[]}
onExit={() => {}}
initialModeState={{ mode: 'list-agents', source: 'all' }}
/>
</AppStateProvider>,
)

try {
const listOutput = await waitForOutput(
listStreams.getOutput,
frame => frame.includes('reviewer') && frame.includes('sdk-helper'),
)
expect(listOutput).toContain('sdk-helper')
} finally {
listRoot.unmount()
listStreams.stdin.end()
listStreams.stdout.end()
}

const menuStreams = createTestStreams()
const menuRoot = await createRoot({
stdout: menuStreams.stdout as unknown as NodeJS.WriteStream,
stdin: menuStreams.stdin as unknown as NodeJS.ReadStream,
patchConsole: false,
})

menuRoot.render(
<AppStateProvider initialState={initialState}>
<AgentsMenu
tools={[]}
onExit={() => {}}
initialModeState={{
mode: 'agent-menu',
agent: sdkHelper,
previousMode: { mode: 'list-agents', source: 'all' },
}}
/>
</AppStateProvider>,
)

try {
const menuOutput = await waitForOutput(menuStreams.getOutput, frame =>
frame.includes('View agent'),
)
expect(menuOutput).not.toContain('Edit agent')
expect(menuOutput).not.toContain('Delete agent')
} finally {
menuRoot.unmount()
menuStreams.stdin.end()
menuStreams.stdout.end()
}
})

test('shows only SDK agents in the dedicated SDK source list', async () => {
const AgentsMenu = await importAgentsMenu()
const reviewer = createAgent('reviewer')
const sdkHelper = createAgent('sdk-helper', 'sdk')
const initialState = {
...getDefaultAppState(),
agentDefinitions: {
activeAgents: [reviewer, sdkHelper],
allAgents: [reviewer, sdkHelper],
},
}
const { stdout, stdin, getOutput } = createTestStreams()
const root = await createRoot({
stdout: stdout as unknown as NodeJS.WriteStream,
stdin: stdin as unknown as NodeJS.ReadStream,
patchConsole: false,
})

root.render(
<AppStateProvider initialState={initialState}>
<AgentsMenu
tools={[]}
onExit={() => {}}
initialModeState={{ mode: 'list-agents', source: 'sdk' }}
/>
</AppStateProvider>,
)

try {
const output = await waitForOutput(getOutput, frame =>
frame.includes('sdk-helper'),
)
expect(output).toContain('sdk-helper')
expect(output).not.toContain('reviewer')
} finally {
root.unmount()
stdin.end()
stdout.end()
}
})
5 changes: 3 additions & 2 deletions src/components/agents/AgentsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export function AgentsMenu(t0) {
localSettings: t7,
flagSettings: t8,
plugin: t9,
sdk: allAgents.filter(a => a.source === "sdk"),
all: allAgents
};
$[16] = allAgents;
Expand Down Expand Up @@ -202,7 +203,7 @@ export function AgentsMenu(t0) {
{
let t13;
if ($[28] !== agentsBySource || $[29] !== modeState.source) {
t13 = modeState.source === "all" ? [...agentsBySource["built-in"], ...agentsBySource.userSettings, ...agentsBySource.projectSettings, ...agentsBySource.localSettings, ...agentsBySource.policySettings, ...agentsBySource.flagSettings, ...agentsBySource.plugin] : agentsBySource[modeState.source];
t13 = modeState.source === "all" ? [...agentsBySource["built-in"], ...agentsBySource.userSettings, ...agentsBySource.projectSettings, ...agentsBySource.localSettings, ...agentsBySource.policySettings, ...agentsBySource.flagSettings, ...agentsBySource.plugin, ...agentsBySource.sdk] : agentsBySource[modeState.source];
$[28] = agentsBySource;
$[29] = modeState.source;
$[30] = t13;
Expand Down Expand Up @@ -320,7 +321,7 @@ export function AgentsMenu(t0) {
}
const freshAgent_1 = t13;
const agentToUse = freshAgent_1 || modeState.agent;
const isEditable = agentToUse.source !== "built-in" && agentToUse.source !== "plugin" && agentToUse.source !== "flagSettings";
const isEditable = agentToUse.source !== "built-in" && agentToUse.source !== "plugin" && agentToUse.source !== "flagSettings" && agentToUse.source !== "sdk";
const isActiveAgent = agentToUse.agentType === activeAgentName;
const sessionAgentToUse = agents.find(a_10 => a_10.agentType === agentToUse.agentType) ?? agentToUse;
const editableItems = isEditable ? [{
Expand Down
6 changes: 6 additions & 0 deletions src/components/agents/agentFileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ export function getActualAgentFilePath(agent: AgentDefinition): string {
if (agent.source === 'plugin') {
throw new Error('Cannot get file path for plugin agents')
}
if (agent.source === 'sdk') {
throw new Error('Cannot get file path for SDK agents')
}

const dirPath = agent.baseDir || getAgentDirectoryPath(agent.source)
const filename = agent.filename || agent.agentType
Expand Down Expand Up @@ -144,6 +147,9 @@ export function getActualRelativeAgentFilePath(agent: AgentDefinition): string {
if (agent.source === 'flagSettings') {
return 'CLI argument'
}
if (agent.source === 'sdk') {
return 'SDK agent'
}

const dirPath =
agent.baseDir &&
Expand Down
2 changes: 1 addition & 1 deletion src/components/agents/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type WithAgent = { agent: AgentDefinition }
// Simplified state type using intersection types
export type ModeState =
| { mode: 'main-menu' }
| { mode: 'list-agents'; source: SettingSource | 'all' | 'built-in' }
| { mode: 'list-agents'; source: SettingSource | 'all' | 'built-in' | 'plugin' | 'sdk' }
| ({ mode: 'agent-menu' } & WithAgent & WithPreviousMode)
| ({ mode: 'view-agent' } & WithAgent & WithPreviousMode)
| { mode: 'create-agent' }
Expand Down
5 changes: 4 additions & 1 deletion src/components/agents/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { SettingSource } from 'src/utils/settings/constants.js'
import { getSettingSourceName } from 'src/utils/settings/constants.js'

export function getAgentSourceDisplayName(
source: SettingSource | 'all' | 'built-in' | 'plugin',
source: SettingSource | 'all' | 'built-in' | 'plugin' | 'sdk',
): string {
if (source === 'all') {
return 'Agents'
Expand All @@ -14,5 +14,8 @@ export function getAgentSourceDisplayName(
if (source === 'plugin') {
return 'Plugin agents'
}
if (source === 'sdk') {
return 'SDK agents'
}
return capitalize(getSettingSourceName(source))
}
23 changes: 22 additions & 1 deletion src/entrypoints/sdk.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,18 @@ export type QueryOptions = {
| { type: 'custom'; content: string }
/** Agent definitions to register with the query engine. */
agents?: Record<string, {
description: string
description?: string
prompt: string
/**
* Tool allowlist for this agent. If omitted or set to ['*'], the agent can use
* all tools available to subagents after disallowedTools is applied.
*/
tools?: string[]
/** Tool denylist for this agent. Deny entries always override tools entries. */
disallowedTools?: string[]
model?: string
maxTurns?: number
maxSteps?: number
}>
settingSources?: string[]
/** When true, yields stream_event messages for token-by-token streaming. */
Expand Down Expand Up @@ -403,6 +409,21 @@ export type SDKSessionOptions = {
onPermissionRequest?: (message: SDKPermissionRequestMessage) => void
/** Tools to disallow (blanket deny by tool name). */
disallowedTools?: string[]
/** Agent definitions to register with the session engine. */
agents?: Record<string, {
description?: string
prompt: string
/**
* Tool allowlist for this agent. If omitted or set to ['*'], the agent can use
* all tools available to subagents after disallowedTools is applied.
*/
tools?: string[]
/** Tool denylist for this agent. Deny entries always override tools entries. */
disallowedTools?: string[]
model?: string
maxTurns?: number
maxSteps?: number
}>
}

export interface SDKSession {
Expand Down
Loading