Skip to content

Commit 9fe911c

Browse files
committed
sdk: update docs, rename allFiles to projectFiles
1 parent 4cb2069 commit 9fe911c

File tree

2 files changed

+48
-20
lines changed

2 files changed

+48
-20
lines changed

sdk/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,38 @@ const run2 = await client.run({
6363
})
6464
```
6565

66+
## API Reference
67+
68+
### `client.run(options)`
69+
70+
Runs a Codebuff agent with the specified options.
71+
72+
#### Parameters
73+
74+
- **`agent`** (string, required): The agent to run. Use `'base'` for the default agent, or specify a custom agent ID if you made your own agent config.
75+
76+
- **`prompt`** (string, required): The user prompt describing what you want the agent to do.
77+
78+
- **`params`** (object, optional): Additional parameters for the agent. Most agents don't use this, but some custom agents can take a JSON object as input in addition to the user prompt string.
79+
80+
- **`handleEvent`** (function, optional): Callback function that receives every event during execution (assistant messages, tool calls, etc.). This allows you to stream the agent's progress in real-time. We will likely add a token-by-token streaming callback in the future.
81+
82+
- **`previousRun`** (object, optional): JSON state returned from a previous `run()` call. Use this to continue a conversation or session with the agent, maintaining context from previous interactions.
83+
84+
- **`projectFiles`** (object, optional): All the files in your project as a plain JavaScript object. Keys should be the full path from your current directory to each file, and values should be the string contents of the file. Example: `{ "src/index.ts": "console.log('hi')" }`. This helps Codebuff pick good source files for context. Note: This parameter was previously named `allFiles` but has been renamed for clarity.
85+
86+
- **`knowledgeFiles`** (object, optional): Knowledge files to inject into every `run()` call. Uses the same schema as `projectFiles` - keys are file paths and values are file contents. These files are added directly to the agent's context.
87+
88+
- **`agentConfig`** (object, optional): If you defined your own custom agent, pass the agent configuration here. The key should be the agent ID (e.g., 'my-custom-agent'), and the value should be the compiled agent configuration. We should provide a utility function to load and compile agents in the future to make this easier.
89+
90+
- **`maxAgentSteps`** (number, optional): Maximum number of steps the agent can take before stopping. Use this as a safety measure in case your agent starts going off the rails. A reasonable number is around 20.
91+
92+
#### Returns
93+
94+
Returns a Promise that resolves to a `RunState` object containing:
95+
- `sessionState`: The current session state that can be passed to subsequent runs
96+
- `toolResults`: Results from any tools that were executed during the run
97+
6698
## License
6799

68100
MIT

sdk/src/client.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,31 +107,27 @@ export class CodebuffClient {
107107
}
108108

109109
/**
110-
* Run an agent.
110+
* Run a Codebuff agent with the specified options.
111111
*
112-
* Pass an agent id, a prompt, and an event handler, plus options.
112+
* @param agent - The agent to run. Use 'base' for the default agent, or specify a custom agent ID if you made your own agent config.
113+
* @param prompt - The user prompt describing what you want the agent to do.
114+
* @param params - (Optional) Additional parameters for the agent. Most agents don't use this, but some custom agents can take a JSON object as input in addition to the user prompt string.
115+
* @param handleEvent - (Optional) Callback function that receives every event during execution (assistant messages, tool calls, etc.). This allows you to stream the agent's progress in real-time. We will likely add a token-by-token streaming callback in the future.
116+
* @param previousRun - (Optional) JSON state returned from a previous run() call. Use this to continue a conversation or session with the agent, maintaining context from previous interactions.
117+
* @param projectFiles - (Optional) All the files in your project as a plain JavaScript object. Keys should be the full path from your current directory to each file, and values should be the string contents of the file. Example: { "src/index.ts": "console.log('hi')" }. This helps Codebuff pick good source files for context.
118+
* @param knowledgeFiles - (Optional) Knowledge files to inject into every run() call. Uses the same schema as projectFiles - keys are file paths and values are file contents. These files are added directly to the agent's context.
119+
* @param agentConfig - (Optional) If you defined your own custom agent, pass the agent configuration here. The key should be the agent ID (e.g., 'my-custom-agent'), and the value should be the compiled agent configuration. We will provide a utility function to load and compile agents in the future to make this easier.
120+
* @param maxAgentSteps - (Optional) Maximum number of steps the agent can take before stopping. Use this as a safety measure in case your agent starts going off the rails. A reasonable number is around 20.
113121
*
114-
* Returns the state of the run, which can be passed to a subsequent run to continue the run.
115-
*
116-
* @param agent - The agent to run, e.g. 'base' or 'codebuff/file-picker@0.0.1'
117-
* @param prompt - The user prompt, e.g. 'Add a console.log to the index file'
118-
* @param params - (Optional) The parameters to pass to the agent.
119-
*
120-
* @param handleEvent - (Optional) A function to handle events.
121-
* @param previousState - (Optional) Continue a previous run with the return value of a previous run.
122-
*
123-
* @param allFiles - (Optional) All the files in the project, in an object of file path to file content. Improves codebuff's ability to locate files.
124-
* @param knowledgeFiles - (Optional) The knowledge files to pass to the agent.
125-
* @param agentTemplates - (Optional) The agent templates to pass to the agent.
126-
* @param maxAgentSteps - (Optional) The maximum number of agent steps the main agent can run before stopping.
122+
* @returns A Promise that resolves to a RunState JSON object which you can pass to a subsequent run() call to continue the run.
127123
*/
128124
public async run({
129125
agent,
130126
prompt,
131127
params,
132128
handleEvent,
133129
previousRun,
134-
allFiles,
130+
projectFiles,
135131
knowledgeFiles,
136132
agentConfig,
137133
maxAgentSteps,
@@ -141,7 +137,7 @@ export class CodebuffClient {
141137
params?: Record<string, any>
142138
handleEvent?: (event: PrintModeEvent) => void
143139
previousRun?: RunState
144-
allFiles?: Record<string, string>
140+
projectFiles?: Record<string, string>
145141
knowledgeFiles?: Record<string, string>
146142
agentConfig?: Record<string, any>
147143
maxAgentSteps?: number
@@ -154,7 +150,7 @@ export class CodebuffClient {
154150
initialSessionState(this.cwd, {
155151
knowledgeFiles,
156152
agentConfig,
157-
allFiles,
153+
projectFiles,
158154
maxAgentSteps,
159155
})
160156
const toolResults = previousRun?.toolResults ?? []
@@ -272,8 +268,8 @@ export class CodebuffClient {
272268
function initialSessionState(
273269
cwd: string,
274270
options: {
275-
// TODO: Parse allFiles into fileTree, fileTokenScores, tokenCallers
276-
allFiles?: Record<string, string>
271+
// TODO: Parse projectFiles into fileTree, fileTokenScores, tokenCallers
272+
projectFiles?: Record<string, string>
277273
knowledgeFiles?: Record<string, string>
278274
agentConfig?: Record<string, any>
279275
maxAgentSteps?: number

0 commit comments

Comments
 (0)