Docs
SDK

SDK API Reference

Comprehensive API reference for the Agentsmith SDK.

This page provides a detailed reference for all the classes, methods, and options available in the Agentsmith SDK.

AgentsmithClient

The main client for interacting with the Agentsmith API.

Constructor

new AgentsmithClient<T>(apiKey, projectId, options)

Parameters:

  • apiKey: string (required)
  • projectId: string (required)
  • options: AgentsmithClientOptions (optional)

AgentsmithClientOptions

PropTypeDefault
agentsmithApiRoot?
string
https://agentsmith.dev
supabaseUrl?
string
-
supabaseAnonKey?
string
-
agentsmithDirectory?
string
./agentsmith
queueOptions?
PQueueOptions
-
fetchStrategy?
FetchStrategy
remote-fallback
logger?
Logger
-
logLevel?
LogLevel
warn
completionLogsDirectory?
string | null
-
completionLogDirTransformer?
(options: object) => string
-

Methods

getPrompt(arg)

Fetches a prompt from Agentsmith.

  • arg: PromptIdentifier<Agency> (required): The identifier for the prompt, e.g., 'my-prompt' or 'my-prompt@1.2.3'.

Returns: Promise<Prompt<Agency, PromptArg>>

shutdown()

Gracefully shuts down the client, ensuring all background operations complete. This is crucial for allowing scripts and serverless functions to exit cleanly.


Prompt

Represents a single, versioned prompt fetched from Agentsmith. It is not constructed directly, but rather returned from agentsmithClient.getPrompt.

Methods

compile(variables, options)

Compiles the prompt with the given variables.

CompileOptions
PropTypeDefault
globals?
Partial<Agency['globals']>
-
CompileResult
PropTypeDefault
finalVariables?
any
-
compiledPrompt?
string
-

execute(variables, options)

Executes the prompt with the given variables. The execute method returns an object with different fields depending on whether streaming is enabled.

ExecuteOptions
PropTypeDefault
config?
CompletionConfig
-
globals?
Partial<Agency['globals']>
-
ExecuteNonStreamingResult
PropTypeDefault
content?
string | null
-
reasoning?
string | null
-
toolCalls?
ToolCall[] | null
-
completion?
OpenrouterNonStreamingResponse
-
response?
Response
-
logUuid?
string
-
compiledPrompt?
string
-
finalVariables?
any
-
ExecuteStreamingResult
PropTypeDefault
tokens?
AsyncGenerator<string | undefined, void, unknown>
-
reasoningTokens?
AsyncGenerator<string | undefined, void, unknown>
-
toolCalls?
AsyncGenerator<ToolCall, void, unknown>
-
stream?
ReadableStream<Uint8Array>
-
completion?
Promise<OpenrouterNonStreamingResponse>
-
response?
Response
-
logUuid?
string
-
compiledPrompt?
string
-
finalVariables?
any
-
CompletionLogDirTransformerOptions
PropTypeDefault
logUuid?
string
-
prompt?
{ name: string; slug: string; uuid: string; }
-
promptVersion?
{ uuid: string; version: string; config: any; content: string; }
-
variables?
Record<string, any>
-
rawInput?
any
-
rawOutput?
any
-