You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-**`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
Copy file name to clipboardExpand all lines: sdk/src/client.ts
+16-20Lines changed: 16 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -107,31 +107,27 @@ export class CodebuffClient {
107
107
}
108
108
109
109
/**
110
-
* Run an agent.
110
+
* Run a Codebuff agent with the specified options.
111
111
*
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.
113
121
*
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.
127
123
*/
128
124
publicasyncrun({
129
125
agent,
130
126
prompt,
131
127
params,
132
128
handleEvent,
133
129
previousRun,
134
-
allFiles,
130
+
projectFiles,
135
131
knowledgeFiles,
136
132
agentConfig,
137
133
maxAgentSteps,
@@ -141,7 +137,7 @@ export class CodebuffClient {
141
137
params?: Record<string,any>
142
138
handleEvent?: (event: PrintModeEvent)=>void
143
139
previousRun?: RunState
144
-
allFiles?: Record<string,string>
140
+
projectFiles?: Record<string,string>
145
141
knowledgeFiles?: Record<string,string>
146
142
agentConfig?: Record<string,any>
147
143
maxAgentSteps?: number
@@ -154,7 +150,7 @@ export class CodebuffClient {
154
150
initialSessionState(this.cwd,{
155
151
knowledgeFiles,
156
152
agentConfig,
157
-
allFiles,
153
+
projectFiles,
158
154
maxAgentSteps,
159
155
})
160
156
consttoolResults=previousRun?.toolResults??[]
@@ -272,8 +268,8 @@ export class CodebuffClient {
272
268
functioninitialSessionState(
273
269
cwd: string,
274
270
options: {
275
-
// TODO: Parse allFiles into fileTree, fileTokenScores, tokenCallers
276
-
allFiles?: Record<string,string>
271
+
// TODO: Parse projectFiles into fileTree, fileTokenScores, tokenCallers
0 commit comments