nimgent
This page is generated from the module’s exported API and ## documentation comments.
Lightweight LLM client: shared types, generation API, and providers.
RunCallbacks
Section titled “RunCallbacks”Optional observers for work owned by the high-level generation loop.
RunCallbacks = object onRetry*: proc (attempt, delayMs: int; error: ref ProviderError) {.closure.} onToolStart*: proc (step: int; call: ContentBlock) {.closure.} onToolFinish*: proc (step: int; call, output: ContentBlock; durationMs: int) {. closure.} onStepFinish*: proc (step: int; result: StepResult) {.closure.} onFinish*: proc (response: ProviderResponse) {.closure.} trace*: TraceSinkAgentEventStream
Section titled “AgentEventStream”Pull-based event stream. result completes with the run response or
fails with the same exception that terminated the event stream.
AgentEventStream = ref object queue*: FutureStream[AgentEvent] result*: Future[ProviderResponse]EmbedResult
Section titled “EmbedResult”Result for embedding one value.
EmbedResult = object value*: string embedding*: seq[float] usage*: EmbeddingUsageEmbedManyResult
Section titled “EmbedManyResult”Result for embedding a batch of values in input order.
EmbedManyResult = object values*: seq[string] embeddings*: seq[seq[float]] usage*: EmbeddingUsageObjectMode
Section titled “ObjectMode”Choose how structured output is requested and recovered.
ObjectMode = enum omAuto, ## native structured output when the provider has it omNative, ## native only; still extracts/validates/repairs omJson, ## prompt + extract JSON from text omTool ## forced submit tool; arguments are the valueObjectSource
Section titled “ObjectSource”Identify how the returned structured value was obtained.
ObjectSource = enum osNative, ## provider-native structured output osText, ## JSON extracted from model text osTool ## value extracted from the submit toolObjectTruncation
Section titled “ObjectTruncation”Choose how truncated structured output is handled.
ObjectTruncation = enum otReject, ## reject locally repaired JSON after max-token truncation otRepair ## accept locally repaired JSON after max-token truncationObjectResult
Section titled “ObjectResult”Structured output together with the provider response and recovery details.
ObjectResult[T] = object value*: T response*: ProviderResponse usage*: Usage repairs*: int attempts*: int locallyRepaired*: bool source*: ObjectSourcePartialObjectCallback
Section titled “PartialObjectCallback”Partial JSON tree. Not schema-valid. Return false to cancel.
PartialObjectCallback = proc (value: JsonNode): bool {.closure.}Procedures
Section titled “Procedures”Read the next event, returning false when the stream is closed.
proc read(stream: AgentEventStream): Future[(bool, AgentEvent)] {. raises: [ValueError, Exception], tags: [RootEffect], forbids: [].}Returns: Future[(bool, AgentEvent)].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
stream |
AgentEventStream |
Close the event stream and stop waiting readers.
proc close(stream: AgentEventStream) {.raises: [Exception], tags: [RootEffect], forbids: [].}Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
stream |
AgentEventStream |
retryDelayMs
Section titled “retryDelayMs”Calculate the next retry delay.
proc retryDelayMs(attempt: int; retryAfterMs = 0): int {.raises: [], tags: [], forbids: [].}Returns: int.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
attempt |
int |
|
retryAfterMs |
inferred |
0 |
embedManyAsync
Section titled “embedManyAsync”Embed strings in one provider batch, preserving input order.
proc embedManyAsync(model: EmbeddingModel; values: seq[string]; maxRetries = 2; abort: AbortCheck = nil; providerOptions = ProviderOptions(); trace: TraceSink = nil): Future[ EmbedManyResult] {.stackTrace: false, raises: [Exception, ValueError, ProviderError, KeyError, CatchableError], tags: [RootEffect, TimeEffect], forbids: [].}Returns: Future[EmbedManyResult].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
model |
EmbeddingModel |
|
values |
seq[string] |
|
maxRetries |
inferred |
2 |
abort |
AbortCheck |
nil |
providerOptions |
inferred |
ProviderOptions() |
trace |
TraceSink |
nil |
embedMany
Section titled “embedMany”Embed a batch of strings in one provider request.
proc embedMany(model: EmbeddingModel; values: seq[string]; maxRetries = 2; abort: AbortCheck = nil; providerOptions = ProviderOptions(); trace: TraceSink = nil): EmbedManyResult {.raises: [ValueError, Exception, OSError, ProviderError, KeyError, CatchableError], tags: [TimeEffect, RootEffect], forbids: [].}Returns: EmbedManyResult.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
model |
EmbeddingModel |
|
values |
seq[string] |
|
maxRetries |
inferred |
2 |
abort |
AbortCheck |
nil |
providerOptions |
inferred |
ProviderOptions() |
trace |
TraceSink |
nil |
embedAsync
Section titled “embedAsync”Embed one string and return its vector with usage information.
proc embedAsync(model: EmbeddingModel; value: string; maxRetries = 2; abort: AbortCheck = nil; providerOptions = ProviderOptions(); trace: TraceSink = nil): Future[EmbedResult] {. stackTrace: false, raises: [Exception, ValueError, ProviderError, KeyError, CatchableError], tags: [RootEffect, TimeEffect], forbids: [].}Returns: Future[EmbedResult].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
model |
EmbeddingModel |
|
value |
string |
|
maxRetries |
inferred |
2 |
abort |
AbortCheck |
nil |
providerOptions |
inferred |
ProviderOptions() |
trace |
TraceSink |
nil |
Synchronously embed one string.
proc embed(model: EmbeddingModel; value: string; maxRetries = 2; abort: AbortCheck = nil; providerOptions = ProviderOptions(); trace: TraceSink = nil): EmbedResult {.raises: [ValueError, Exception, OSError, ProviderError, KeyError, CatchableError], tags: [TimeEffect, RootEffect], forbids: [].}Returns: EmbedResult.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
model |
EmbeddingModel |
|
value |
string |
|
maxRetries |
inferred |
2 |
abort |
AbortCheck |
nil |
providerOptions |
inferred |
ProviderOptions() |
trace |
TraceSink |
nil |
toolError
Section titled “toolError”Construct a machine-readable local tool failure.
proc toolError(code, message: string; details: JsonNode = nil; retryable = false): ToolError {. raises: [], tags: [], forbids: [].}Returns: ToolError.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
code |
string |
|
message |
string |
|
details |
JsonNode |
nil |
retryable |
inferred |
false |
toolFailure
Section titled “toolFailure”Construct a failed tool result. The optional output is what the model sees; by default it receives the error message.
proc toolFailure(code, message: string; details: JsonNode = nil; retryable = false; output = ""): ToolResult {.raises: [], tags: [], forbids: [].}Returns: ToolResult.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
code |
string |
|
message |
string |
|
details |
JsonNode |
nil |
retryable |
inferred |
false |
output |
inferred |
"" |
tool (overload 1)
Section titled “tool (overload 1)”Typed tool with access to per-call identity, cancellation and metadata.
proc tool[Input, Output](name, description: string; execute: proc ( context: ToolContext; input: Input): Output {.closure.}; parallel = false): ToolType parameters: Input, Output.
Returns: Tool.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
name |
string |
|
description |
string |
|
execute |
proc (context: ToolContext; input: Input): Output {.closure.} |
|
parallel |
inferred |
false |
tool (overload 2)
Section titled “tool (overload 2)”Typed async tool with access to per-call identity, cancellation and metadata.
proc tool[Input, Output](name, description: string; execute: proc ( context: ToolContext; input: Input): Future[Output] {.closure.}; parallel = false): ToolType parameters: Input, Output.
Returns: Tool.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
name |
string |
|
description |
string |
|
execute |
proc (context: ToolContext; input: Input): Future[Output] {.closure.} |
|
parallel |
inferred |
false |
generateTextAsync (overload 1)
Section titled “generateTextAsync (overload 1)”Generate text and optionally run tools for one model turn.
proc generateTextAsync(model: LanguageModel; prompt = ""; messages: seq[Message] = @[]; system = ""; tools: seq[Tool] = @[]; maxTokens = 0; conversationId = ""; generationOptions = GenerationOptions(); maxRetries = 2; maxSteps = 1; abort: AbortCheck = nil; callbacks = RunCallbacks(); providerOptions = ProviderOptions(); metadata: JsonNode = nil; turnId = ""; toolChoice = toolChoiceAuto()): Future[ProviderResponse] {. stackTrace: false, raises: [Exception, ValueError, ProviderError, KeyError, CatchableError], tags: [RootEffect, TimeEffect], forbids: [].}Returns: Future[ProviderResponse].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
model |
LanguageModel |
|
prompt |
inferred |
"" |
messages |
seq[Message] |
@[] |
system |
inferred |
"" |
tools |
seq[Tool] |
@[] |
maxTokens |
inferred |
0 |
conversationId |
inferred |
"" |
generationOptions |
inferred |
GenerationOptions() |
maxRetries |
inferred |
2 |
maxSteps |
inferred |
1 |
abort |
AbortCheck |
nil |
callbacks |
inferred |
RunCallbacks() |
providerOptions |
inferred |
ProviderOptions() |
metadata |
JsonNode |
nil |
turnId |
inferred |
"" |
toolChoice |
inferred |
toolChoiceAuto() |
generateText (overload 1)
Section titled “generateText (overload 1)”Synchronously generate text and optionally run tools.
proc generateText(model: LanguageModel; prompt = ""; messages: seq[Message] = @[]; system = ""; tools: seq[Tool] = @[]; maxTokens = 0; conversationId = ""; generationOptions = GenerationOptions(); maxRetries = 2; maxSteps = 1; abort: AbortCheck = nil; callbacks = RunCallbacks(); providerOptions = ProviderOptions(); metadata: JsonNode = nil; turnId = ""; toolChoice = toolChoiceAuto()): ProviderResponse {.raises: [ ValueError, Exception, OSError, ProviderError, KeyError, CatchableError], tags: [TimeEffect, RootEffect], forbids: [].}Returns: ProviderResponse.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
model |
LanguageModel |
|
prompt |
inferred |
"" |
messages |
seq[Message] |
@[] |
system |
inferred |
"" |
tools |
seq[Tool] |
@[] |
maxTokens |
inferred |
0 |
conversationId |
inferred |
"" |
generationOptions |
inferred |
GenerationOptions() |
maxRetries |
inferred |
2 |
maxSteps |
inferred |
1 |
abort |
AbortCheck |
nil |
callbacks |
inferred |
RunCallbacks() |
providerOptions |
inferred |
ProviderOptions() |
metadata |
JsonNode |
nil |
turnId |
inferred |
"" |
toolChoice |
inferred |
toolChoiceAuto() |
generateTextAsync (overload 2)
Section titled “generateTextAsync (overload 2)”Generate text from a ready-made provider request without a tool loop.
Retry wrapper for a ready-made request. Does not run the tool loop
(maxSteps 1); the caller owns tools.
proc generateTextAsync(provider: Provider; request: ProviderRequest; maxRetries = 2; abort: AbortCheck = nil; callbacks = RunCallbacks(); providerOptions = ProviderOptions()): Future[ ProviderResponse] {.stackTrace: false, raises: [Exception, ValueError, ProviderError, KeyError, CatchableError], tags: [RootEffect, TimeEffect], forbids: [].}Returns: Future[ProviderResponse].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
provider |
Provider |
|
request |
ProviderRequest |
|
maxRetries |
inferred |
2 |
abort |
AbortCheck |
nil |
callbacks |
inferred |
RunCallbacks() |
providerOptions |
inferred |
ProviderOptions() |
generateText (overload 2)
Section titled “generateText (overload 2)”Synchronously execute a ready-made provider request without a tool loop.
proc generateText(provider: Provider; request: ProviderRequest; maxRetries = 2; abort: AbortCheck = nil; callbacks = RunCallbacks(); providerOptions = ProviderOptions()): ProviderResponse {.raises: [ ValueError, Exception, OSError, ProviderError, KeyError, CatchableError], tags: [TimeEffect, RootEffect], forbids: [].}Returns: ProviderResponse.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
provider |
Provider |
|
request |
ProviderRequest |
|
maxRetries |
inferred |
2 |
abort |
AbortCheck |
nil |
callbacks |
inferred |
RunCallbacks() |
providerOptions |
inferred |
ProviderOptions() |
streamTextAsync (overload 1)
Section titled “streamTextAsync (overload 1)”Stream text deltas from a language model and optionally run tools.
proc streamTextAsync(model: LanguageModel; onEvent: StreamCallback; prompt = ""; messages: seq[Message] = @[]; system = ""; tools: seq[Tool] = @[]; maxTokens = 0; conversationId = ""; generationOptions = GenerationOptions(); wakeFd: cint = -1; maxRetries = 2; maxSteps = 1; abort: AbortCheck = nil; callbacks = RunCallbacks(); providerOptions = ProviderOptions(); metadata: JsonNode = nil; turnId = ""; toolChoice = toolChoiceAuto()): Future[ProviderResponse] {. stackTrace: false, raises: [Exception, ValueError, ProviderError, KeyError, CatchableError], tags: [RootEffect, TimeEffect], forbids: [].}Returns: Future[ProviderResponse].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
model |
LanguageModel |
|
onEvent |
StreamCallback |
|
prompt |
inferred |
"" |
messages |
seq[Message] |
@[] |
system |
inferred |
"" |
tools |
seq[Tool] |
@[] |
maxTokens |
inferred |
0 |
conversationId |
inferred |
"" |
generationOptions |
inferred |
GenerationOptions() |
wakeFd |
cint |
-1 |
maxRetries |
inferred |
2 |
maxSteps |
inferred |
1 |
abort |
AbortCheck |
nil |
callbacks |
inferred |
RunCallbacks() |
providerOptions |
inferred |
ProviderOptions() |
metadata |
JsonNode |
nil |
turnId |
inferred |
"" |
toolChoice |
inferred |
toolChoiceAuto() |
streamText (overload 1)
Section titled “streamText (overload 1)”Synchronously stream text deltas from a language model.
proc streamText(model: LanguageModel; onEvent: StreamCallback; prompt = ""; messages: seq[Message] = @[]; system = ""; tools: seq[Tool] = @[]; maxTokens = 0; conversationId = ""; generationOptions = GenerationOptions(); wakeFd: cint = -1; maxRetries = 2; maxSteps = 1; abort: AbortCheck = nil; callbacks = RunCallbacks(); providerOptions = ProviderOptions(); metadata: JsonNode = nil; turnId = ""; toolChoice = toolChoiceAuto()): ProviderResponse {.raises: [ ValueError, Exception, OSError, ProviderError, KeyError, CatchableError], tags: [TimeEffect, RootEffect], forbids: [].}Returns: ProviderResponse.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
model |
LanguageModel |
|
onEvent |
StreamCallback |
|
prompt |
inferred |
"" |
messages |
seq[Message] |
@[] |
system |
inferred |
"" |
tools |
seq[Tool] |
@[] |
maxTokens |
inferred |
0 |
conversationId |
inferred |
"" |
generationOptions |
inferred |
GenerationOptions() |
wakeFd |
cint |
-1 |
maxRetries |
inferred |
2 |
maxSteps |
inferred |
1 |
abort |
AbortCheck |
nil |
callbacks |
inferred |
RunCallbacks() |
providerOptions |
inferred |
ProviderOptions() |
metadata |
JsonNode |
nil |
turnId |
inferred |
"" |
toolChoice |
inferred |
toolChoiceAuto() |
streamTextAsync (overload 2)
Section titled “streamTextAsync (overload 2)”Stream a ready-made provider request without a tool loop. Streaming retry wrapper for a ready-made request. No tool loop.
proc streamTextAsync(provider: Provider; request: ProviderRequest; onEvent: StreamCallback; maxRetries = 2; abort: AbortCheck = nil; callbacks = RunCallbacks(); providerOptions = ProviderOptions()): Future[ ProviderResponse] {.stackTrace: false, raises: [Exception, ValueError, ProviderError, KeyError, CatchableError], tags: [RootEffect, TimeEffect], forbids: [].}Returns: Future[ProviderResponse].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
provider |
Provider |
|
request |
ProviderRequest |
|
onEvent |
StreamCallback |
|
maxRetries |
inferred |
2 |
abort |
AbortCheck |
nil |
callbacks |
inferred |
RunCallbacks() |
providerOptions |
inferred |
ProviderOptions() |
streamText (overload 2)
Section titled “streamText (overload 2)”Synchronously stream a ready-made provider request without a tool loop.
proc streamText(provider: Provider; request: ProviderRequest; onEvent: StreamCallback; maxRetries = 2; abort: AbortCheck = nil; callbacks = RunCallbacks(); providerOptions = ProviderOptions()): ProviderResponse {.raises: [ ValueError, Exception, OSError, ProviderError, KeyError, CatchableError], tags: [TimeEffect, RootEffect], forbids: [].}Returns: ProviderResponse.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
provider |
Provider |
|
request |
ProviderRequest |
|
onEvent |
StreamCallback |
|
maxRetries |
inferred |
2 |
abort |
AbortCheck |
nil |
callbacks |
inferred |
RunCallbacks() |
providerOptions |
inferred |
ProviderOptions() |
generateAgentTextAsync
Section titled “generateAgentTextAsync”Run a model with tools and agent lifecycle events.
proc generateAgentTextAsync(model: LanguageModel; prompt = ""; messages: seq[Message] = @[]; system = ""; tools: seq[Tool] = @[]; maxTokens = 0; conversationId = ""; generationOptions = GenerationOptions(); maxRetries = 2; maxSteps = 1; abort: AbortCheck = nil; callbacks = RunCallbacks(); providerOptions = ProviderOptions(); metadata: JsonNode = nil; turnId = ""; toolChoice = toolChoiceAuto(); onEvent: AgentEventCallback = nil; approvalPolicy: ToolApprovalPolicy = nil): Future[ ProviderResponse] {.stackTrace: false, raises: [Exception, ValueError, ProviderError, KeyError, CatchableError], tags: [RootEffect, TimeEffect], forbids: [].}Returns: Future[ProviderResponse].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
model |
LanguageModel |
|
prompt |
inferred |
"" |
messages |
seq[Message] |
@[] |
system |
inferred |
"" |
tools |
seq[Tool] |
@[] |
maxTokens |
inferred |
0 |
conversationId |
inferred |
"" |
generationOptions |
inferred |
GenerationOptions() |
maxRetries |
inferred |
2 |
maxSteps |
inferred |
1 |
abort |
AbortCheck |
nil |
callbacks |
inferred |
RunCallbacks() |
providerOptions |
inferred |
ProviderOptions() |
metadata |
JsonNode |
nil |
turnId |
inferred |
"" |
toolChoice |
inferred |
toolChoiceAuto() |
onEvent |
AgentEventCallback |
nil |
approvalPolicy |
ToolApprovalPolicy |
nil |
streamAgentTextAsync
Section titled “streamAgentTextAsync”Stream an agent run with lifecycle events and tool execution.
proc streamAgentTextAsync(model: LanguageModel; prompt = ""; messages: seq[Message] = @[]; system = ""; tools: seq[Tool] = @[]; maxTokens = 0; conversationId = ""; generationOptions = GenerationOptions(); wakeFd: cint = -1; maxRetries = 2; maxSteps = 1; abort: AbortCheck = nil; callbacks = RunCallbacks(); providerOptions = ProviderOptions(); metadata: JsonNode = nil; turnId = ""; toolChoice = toolChoiceAuto(); onEvent: AgentEventCallback = nil; approvalPolicy: ToolApprovalPolicy = nil): Future[ ProviderResponse] {.stackTrace: false, raises: [Exception, ValueError, ProviderError, KeyError, CatchableError], tags: [RootEffect, TimeEffect], forbids: [].}Returns: Future[ProviderResponse].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
model |
LanguageModel |
|
prompt |
inferred |
"" |
messages |
seq[Message] |
@[] |
system |
inferred |
"" |
tools |
seq[Tool] |
@[] |
maxTokens |
inferred |
0 |
conversationId |
inferred |
"" |
generationOptions |
inferred |
GenerationOptions() |
wakeFd |
cint |
-1 |
maxRetries |
inferred |
2 |
maxSteps |
inferred |
1 |
abort |
AbortCheck |
nil |
callbacks |
inferred |
RunCallbacks() |
providerOptions |
inferred |
ProviderOptions() |
metadata |
JsonNode |
nil |
turnId |
inferred |
"" |
toolChoice |
inferred |
toolChoiceAuto() |
onEvent |
AgentEventCallback |
nil |
approvalPolicy |
ToolApprovalPolicy |
nil |
eventStream
Section titled “eventStream”Adapt an event-callback run into a pull-based event stream.
proc eventStream(run: proc (callback: AgentEventCallback): Future[ ProviderResponse] {.closure.}): AgentEventStream {. raises: [Exception, ValueError], tags: [RootEffect], forbids: [].}Returns: AgentEventStream.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
run |
proc (callback: AgentEventCallback): Future[ProviderResponse] {.closure.} |
generateTextAsync (overload 3)
Section titled “generateTextAsync (overload 3)”Generate text while receiving agent lifecycle events.
proc generateTextAsync(model: LanguageModel; onEvent: AgentEventCallback; prompt = ""; messages: seq[Message] = @[]; system = ""; tools: seq[Tool] = @[]; maxTokens = 0; conversationId = ""; generationOptions = GenerationOptions(); maxRetries = 2; maxSteps = 1; abort: AbortCheck = nil; callbacks = RunCallbacks(); providerOptions = ProviderOptions(); metadata: JsonNode = nil; turnId = ""; toolChoice = toolChoiceAuto(); approvalPolicy: ToolApprovalPolicy = nil): Future[ ProviderResponse] {.stackTrace: false, raises: [Exception, ValueError, ProviderError, KeyError, CatchableError], tags: [RootEffect, TimeEffect], forbids: [].}Returns: Future[ProviderResponse].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
model |
LanguageModel |
|
onEvent |
AgentEventCallback |
|
prompt |
inferred |
"" |
messages |
seq[Message] |
@[] |
system |
inferred |
"" |
tools |
seq[Tool] |
@[] |
maxTokens |
inferred |
0 |
conversationId |
inferred |
"" |
generationOptions |
inferred |
GenerationOptions() |
maxRetries |
inferred |
2 |
maxSteps |
inferred |
1 |
abort |
AbortCheck |
nil |
callbacks |
inferred |
RunCallbacks() |
providerOptions |
inferred |
ProviderOptions() |
metadata |
JsonNode |
nil |
turnId |
inferred |
"" |
toolChoice |
inferred |
toolChoiceAuto() |
approvalPolicy |
ToolApprovalPolicy |
nil |
generateText (overload 3)
Section titled “generateText (overload 3)”Synchronously generate text while receiving agent lifecycle events.
proc generateText(model: LanguageModel; onEvent: AgentEventCallback; prompt = ""; messages: seq[Message] = @[]; system = ""; tools: seq[Tool] = @[]; maxTokens = 0; conversationId = ""; generationOptions = GenerationOptions(); maxRetries = 2; maxSteps = 1; abort: AbortCheck = nil; callbacks = RunCallbacks(); providerOptions = ProviderOptions(); metadata: JsonNode = nil; turnId = ""; toolChoice = toolChoiceAuto(); approvalPolicy: ToolApprovalPolicy = nil): ProviderResponse {.raises: [ ValueError, Exception, OSError, ProviderError, KeyError, CatchableError], tags: [TimeEffect, RootEffect], forbids: [].}Returns: ProviderResponse.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
model |
LanguageModel |
|
onEvent |
AgentEventCallback |
|
prompt |
inferred |
"" |
messages |
seq[Message] |
@[] |
system |
inferred |
"" |
tools |
seq[Tool] |
@[] |
maxTokens |
inferred |
0 |
conversationId |
inferred |
"" |
generationOptions |
inferred |
GenerationOptions() |
maxRetries |
inferred |
2 |
maxSteps |
inferred |
1 |
abort |
AbortCheck |
nil |
callbacks |
inferred |
RunCallbacks() |
providerOptions |
inferred |
ProviderOptions() |
metadata |
JsonNode |
nil |
turnId |
inferred |
"" |
toolChoice |
inferred |
toolChoiceAuto() |
approvalPolicy |
ToolApprovalPolicy |
nil |
streamTextAsync (overload 3)
Section titled “streamTextAsync (overload 3)”Stream text while receiving agent lifecycle events.
proc streamTextAsync(model: LanguageModel; onEvent: AgentEventCallback; prompt = ""; messages: seq[Message] = @[]; system = ""; tools: seq[Tool] = @[]; maxTokens = 0; conversationId = ""; generationOptions = GenerationOptions(); wakeFd: cint = -1; maxRetries = 2; maxSteps = 1; abort: AbortCheck = nil; callbacks = RunCallbacks(); providerOptions = ProviderOptions(); metadata: JsonNode = nil; turnId = ""; toolChoice = toolChoiceAuto(); approvalPolicy: ToolApprovalPolicy = nil): Future[ ProviderResponse] {.stackTrace: false, raises: [Exception, ValueError, ProviderError, KeyError, CatchableError], tags: [RootEffect, TimeEffect], forbids: [].}Returns: Future[ProviderResponse].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
model |
LanguageModel |
|
onEvent |
AgentEventCallback |
|
prompt |
inferred |
"" |
messages |
seq[Message] |
@[] |
system |
inferred |
"" |
tools |
seq[Tool] |
@[] |
maxTokens |
inferred |
0 |
conversationId |
inferred |
"" |
generationOptions |
inferred |
GenerationOptions() |
wakeFd |
cint |
-1 |
maxRetries |
inferred |
2 |
maxSteps |
inferred |
1 |
abort |
AbortCheck |
nil |
callbacks |
inferred |
RunCallbacks() |
providerOptions |
inferred |
ProviderOptions() |
metadata |
JsonNode |
nil |
turnId |
inferred |
"" |
toolChoice |
inferred |
toolChoiceAuto() |
approvalPolicy |
ToolApprovalPolicy |
nil |
streamText (overload 3)
Section titled “streamText (overload 3)”Synchronously stream text while receiving agent lifecycle events.
proc streamText(model: LanguageModel; onEvent: AgentEventCallback; prompt = ""; messages: seq[Message] = @[]; system = ""; tools: seq[Tool] = @[]; maxTokens = 0; conversationId = ""; generationOptions = GenerationOptions(); wakeFd: cint = -1; maxRetries = 2; maxSteps = 1; abort: AbortCheck = nil; callbacks = RunCallbacks(); providerOptions = ProviderOptions(); metadata: JsonNode = nil; turnId = ""; toolChoice = toolChoiceAuto(); approvalPolicy: ToolApprovalPolicy = nil): ProviderResponse {.raises: [ ValueError, Exception, OSError, ProviderError, KeyError, CatchableError], tags: [TimeEffect, RootEffect], forbids: [].}Returns: ProviderResponse.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
model |
LanguageModel |
|
onEvent |
AgentEventCallback |
|
prompt |
inferred |
"" |
messages |
seq[Message] |
@[] |
system |
inferred |
"" |
tools |
seq[Tool] |
@[] |
maxTokens |
inferred |
0 |
conversationId |
inferred |
"" |
generationOptions |
inferred |
GenerationOptions() |
wakeFd |
cint |
-1 |
maxRetries |
inferred |
2 |
maxSteps |
inferred |
1 |
abort |
AbortCheck |
nil |
callbacks |
inferred |
RunCallbacks() |
providerOptions |
inferred |
ProviderOptions() |
metadata |
JsonNode |
nil |
turnId |
inferred |
"" |
toolChoice |
inferred |
toolChoiceAuto() |
approvalPolicy |
ToolApprovalPolicy |
nil |
generateTextAsync (overload 4)
Section titled “generateTextAsync (overload 4)”Generate a ready-made request while receiving agent lifecycle events.
proc generateTextAsync(provider: Provider; request: ProviderRequest; onEvent: AgentEventCallback; maxRetries = 2; abort: AbortCheck = nil; callbacks = RunCallbacks(); providerOptions = ProviderOptions()): Future[ ProviderResponse] {.stackTrace: false, raises: [Exception, ValueError, ProviderError, KeyError, CatchableError], tags: [RootEffect, TimeEffect], forbids: [].}Returns: Future[ProviderResponse].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
provider |
Provider |
|
request |
ProviderRequest |
|
onEvent |
AgentEventCallback |
|
maxRetries |
inferred |
2 |
abort |
AbortCheck |
nil |
callbacks |
inferred |
RunCallbacks() |
providerOptions |
inferred |
ProviderOptions() |
generateText (overload 4)
Section titled “generateText (overload 4)”Synchronously generate a ready-made request with agent lifecycle events.
proc generateText(provider: Provider; request: ProviderRequest; onEvent: AgentEventCallback; maxRetries = 2; abort: AbortCheck = nil; callbacks = RunCallbacks(); providerOptions = ProviderOptions()): ProviderResponse {.raises: [ ValueError, Exception, OSError, ProviderError, KeyError, CatchableError], tags: [TimeEffect, RootEffect], forbids: [].}Returns: ProviderResponse.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
provider |
Provider |
|
request |
ProviderRequest |
|
onEvent |
AgentEventCallback |
|
maxRetries |
inferred |
2 |
abort |
AbortCheck |
nil |
callbacks |
inferred |
RunCallbacks() |
providerOptions |
inferred |
ProviderOptions() |
streamTextAsync (overload 4)
Section titled “streamTextAsync (overload 4)”Stream a ready-made request while receiving agent lifecycle events.
proc streamTextAsync(provider: Provider; request: ProviderRequest; onEvent: AgentEventCallback; maxRetries = 2; abort: AbortCheck = nil; callbacks = RunCallbacks(); providerOptions = ProviderOptions()): Future[ ProviderResponse] {.stackTrace: false, raises: [Exception, ValueError, ProviderError, KeyError, CatchableError], tags: [RootEffect, TimeEffect], forbids: [].}Returns: Future[ProviderResponse].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
provider |
Provider |
|
request |
ProviderRequest |
|
onEvent |
AgentEventCallback |
|
maxRetries |
inferred |
2 |
abort |
AbortCheck |
nil |
callbacks |
inferred |
RunCallbacks() |
providerOptions |
inferred |
ProviderOptions() |
streamText (overload 4)
Section titled “streamText (overload 4)”Synchronously stream a ready-made request with agent lifecycle events.
proc streamText(provider: Provider; request: ProviderRequest; onEvent: AgentEventCallback; maxRetries = 2; abort: AbortCheck = nil; callbacks = RunCallbacks(); providerOptions = ProviderOptions()): ProviderResponse {.raises: [ ValueError, Exception, OSError, ProviderError, KeyError, CatchableError], tags: [TimeEffect, RootEffect], forbids: [].}Returns: ProviderResponse.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
provider |
Provider |
|
request |
ProviderRequest |
|
onEvent |
AgentEventCallback |
|
maxRetries |
inferred |
2 |
abort |
AbortCheck |
nil |
callbacks |
inferred |
RunCallbacks() |
providerOptions |
inferred |
ProviderOptions() |
events
Section titled “events”Start a pull-based event stream for an agent run.
proc events(model: LanguageModel; prompt = ""; messages: seq[Message] = @[]; system = ""; tools: seq[Tool] = @[]; maxTokens = 0; conversationId = ""; generationOptions = GenerationOptions(); maxRetries = 2; maxSteps = 1; abort: AbortCheck = nil; callbacks = RunCallbacks(); providerOptions = ProviderOptions(); metadata: JsonNode = nil; turnId = ""; toolChoice = toolChoiceAuto(); approvalPolicy: ToolApprovalPolicy = nil): AgentEventStream {. raises: [Exception, ValueError], tags: [RootEffect], forbids: [].}Returns: AgentEventStream.
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
model |
LanguageModel |
|
prompt |
inferred |
"" |
messages |
seq[Message] |
@[] |
system |
inferred |
"" |
tools |
seq[Tool] |
@[] |
maxTokens |
inferred |
0 |
conversationId |
inferred |
"" |
generationOptions |
inferred |
GenerationOptions() |
maxRetries |
inferred |
2 |
maxSteps |
inferred |
1 |
abort |
AbortCheck |
nil |
callbacks |
inferred |
RunCallbacks() |
providerOptions |
inferred |
ProviderOptions() |
metadata |
JsonNode |
nil |
turnId |
inferred |
"" |
toolChoice |
inferred |
toolChoiceAuto() |
approvalPolicy |
ToolApprovalPolicy |
nil |
generateObjectAsync (overload 1)
Section titled “generateObjectAsync (overload 1)”Generate JSON that matches a supplied schema.
proc generateObjectAsync(model: LanguageModel; schema: JsonNode; prompt = ""; messages: seq[Message] = @[]; system = ""; name = "object"; description = ""; maxTokens = 0; conversationId = ""; generationOptions = GenerationOptions(); maxRetries = 2; maxRepairs = 0; mode = omAuto; abort: AbortCheck = nil; providerOptions = ProviderOptions(); truncation = otReject; trace: TraceSink = nil): Future[ ObjectResult[JsonNode]] {.stackTrace: false, raises: [Exception, ValueError, ProviderError, KeyError, ObjectError, CatchableError], tags: [RootEffect, TimeEffect, ReadIOEffect, WriteIOEffect], forbids: [].}Returns: Future[ObjectResult[JsonNode]].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
model |
LanguageModel |
|
schema |
JsonNode |
|
prompt |
inferred |
"" |
messages |
seq[Message] |
@[] |
system |
inferred |
"" |
name |
inferred |
"object" |
description |
inferred |
"" |
maxTokens |
inferred |
0 |
conversationId |
inferred |
"" |
generationOptions |
inferred |
GenerationOptions() |
maxRetries |
inferred |
2 |
maxRepairs |
inferred |
0 |
mode |
inferred |
omAuto |
abort |
AbortCheck |
nil |
providerOptions |
inferred |
ProviderOptions() |
truncation |
inferred |
otReject |
trace |
TraceSink |
nil |
generateObject (overload 1)
Section titled “generateObject (overload 1)”Synchronously generate JSON that matches a supplied schema.
proc generateObject(model: LanguageModel; schema: JsonNode; prompt = ""; messages: seq[Message] = @[]; system = ""; name = "object"; description = ""; maxTokens = 0; conversationId = ""; generationOptions = GenerationOptions(); maxRetries = 2; maxRepairs = 0; mode = omAuto; abort: AbortCheck = nil; providerOptions = ProviderOptions(); truncation = otReject; trace: TraceSink = nil): ObjectResult[JsonNode] {.raises: [ ValueError, Exception, OSError, ProviderError, KeyError, ObjectError, CatchableError], tags: [TimeEffect, RootEffect, ReadIOEffect, WriteIOEffect], forbids: [].}Returns: ObjectResult[JsonNode].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
model |
LanguageModel |
|
schema |
JsonNode |
|
prompt |
inferred |
"" |
messages |
seq[Message] |
@[] |
system |
inferred |
"" |
name |
inferred |
"object" |
description |
inferred |
"" |
maxTokens |
inferred |
0 |
conversationId |
inferred |
"" |
generationOptions |
inferred |
GenerationOptions() |
maxRetries |
inferred |
2 |
maxRepairs |
inferred |
0 |
mode |
inferred |
omAuto |
abort |
AbortCheck |
nil |
providerOptions |
inferred |
ProviderOptions() |
truncation |
inferred |
otReject |
trace |
TraceSink |
nil |
streamObjectAsync (overload 1)
Section titled “streamObjectAsync (overload 1)”Stream a model’s structured response using a generated JSON schema.
proc streamObjectAsync(model: LanguageModel; schema: JsonNode; prompt = ""; messages: seq[Message] = @[]; system = ""; name = "object"; description = ""; maxTokens = 0; conversationId = ""; generationOptions = GenerationOptions(); wakeFd: cint = -1; maxRetries = 2; maxRepairs = 0; mode = omAuto; abort: AbortCheck = nil; onPartial: PartialObjectCallback = nil; onEvent: StreamCallback = nil; providerOptions = ProviderOptions(); truncation = otReject; trace: TraceSink = nil): Future[ ObjectResult[JsonNode]] {.stackTrace: false, raises: [Exception, ValueError, ProviderError, KeyError, ObjectError, CatchableError, CancelledError], tags: [ RootEffect, TimeEffect, ReadIOEffect, WriteIOEffect], forbids: [].}Returns: Future[ObjectResult[JsonNode]].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
model |
LanguageModel |
|
schema |
JsonNode |
|
prompt |
inferred |
"" |
messages |
seq[Message] |
@[] |
system |
inferred |
"" |
name |
inferred |
"object" |
description |
inferred |
"" |
maxTokens |
inferred |
0 |
conversationId |
inferred |
"" |
generationOptions |
inferred |
GenerationOptions() |
wakeFd |
cint |
-1 |
maxRetries |
inferred |
2 |
maxRepairs |
inferred |
0 |
mode |
inferred |
omAuto |
abort |
AbortCheck |
nil |
onPartial |
PartialObjectCallback |
nil |
onEvent |
StreamCallback |
nil |
providerOptions |
inferred |
ProviderOptions() |
truncation |
inferred |
otReject |
trace |
TraceSink |
nil |
streamObject (overload 1)
Section titled “streamObject (overload 1)”Synchronously stream a model’s structured response.
proc streamObject(model: LanguageModel; schema: JsonNode; prompt = ""; messages: seq[Message] = @[]; system = ""; name = "object"; description = ""; maxTokens = 0; conversationId = ""; generationOptions = GenerationOptions(); wakeFd: cint = -1; maxRetries = 2; maxRepairs = 0; mode = omAuto; abort: AbortCheck = nil; onPartial: PartialObjectCallback = nil; onEvent: StreamCallback = nil; providerOptions = ProviderOptions(); truncation = otReject; trace: TraceSink = nil): ObjectResult[JsonNode] {.raises: [ ValueError, Exception, OSError, ProviderError, KeyError, ObjectError, CatchableError, CancelledError], tags: [TimeEffect, RootEffect, ReadIOEffect, WriteIOEffect], forbids: [].}Returns: ObjectResult[JsonNode].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
model |
LanguageModel |
|
schema |
JsonNode |
|
prompt |
inferred |
"" |
messages |
seq[Message] |
@[] |
system |
inferred |
"" |
name |
inferred |
"object" |
description |
inferred |
"" |
maxTokens |
inferred |
0 |
conversationId |
inferred |
"" |
generationOptions |
inferred |
GenerationOptions() |
wakeFd |
cint |
-1 |
maxRetries |
inferred |
2 |
maxRepairs |
inferred |
0 |
mode |
inferred |
omAuto |
abort |
AbortCheck |
nil |
onPartial |
PartialObjectCallback |
nil |
onEvent |
StreamCallback |
nil |
providerOptions |
inferred |
ProviderOptions() |
truncation |
inferred |
otReject |
trace |
TraceSink |
nil |
toObject
Section titled “toObject”Decode r.value as T. Validation already ran against the schema.
proc toObject[T](r: ObjectResult[JsonNode]): ObjectResult[T]Type parameters: T.
Returns: ObjectResult[T].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
r |
ObjectResult[JsonNode] |
generateObjectAsync (overload 2)
Section titled “generateObjectAsync (overload 2)”Generate structured output and decode it into T.
generateObject with jsonSchema(T), then toObject.
proc generateObjectAsync[T](model: LanguageModel; prompt = ""; messages: seq[Message] = @[]; system = ""; name = ""; description = ""; maxTokens = 0; conversationId = ""; generationOptions = GenerationOptions(); maxRetries = 2; maxRepairs = 0; mode = omAuto; abort: AbortCheck = nil; providerOptions = ProviderOptions(); truncation = otReject; trace: TraceSink = nil): Future[ ObjectResult[T]] {.stackTrace: false.}Type parameters: T.
Returns: Future[ObjectResult[T]].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
model |
LanguageModel |
|
prompt |
inferred |
"" |
messages |
seq[Message] |
@[] |
system |
inferred |
"" |
name |
inferred |
"" |
description |
inferred |
"" |
maxTokens |
inferred |
0 |
conversationId |
inferred |
"" |
generationOptions |
inferred |
GenerationOptions() |
maxRetries |
inferred |
2 |
maxRepairs |
inferred |
0 |
mode |
inferred |
omAuto |
abort |
AbortCheck |
nil |
providerOptions |
inferred |
ProviderOptions() |
truncation |
inferred |
otReject |
trace |
TraceSink |
nil |
generateObject (overload 2)
Section titled “generateObject (overload 2)”Synchronously generate structured output and decode it into T.
proc generateObject[T](model: LanguageModel; prompt = ""; messages: seq[Message] = @[]; system = ""; name = ""; description = ""; maxTokens = 0; conversationId = ""; generationOptions = GenerationOptions(); maxRetries = 2; maxRepairs = 0; mode = omAuto; abort: AbortCheck = nil; providerOptions = ProviderOptions(); truncation = otReject; trace: TraceSink = nil): ObjectResult[ T]Type parameters: T.
Returns: ObjectResult[T].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
model |
LanguageModel |
|
prompt |
inferred |
"" |
messages |
seq[Message] |
@[] |
system |
inferred |
"" |
name |
inferred |
"" |
description |
inferred |
"" |
maxTokens |
inferred |
0 |
conversationId |
inferred |
"" |
generationOptions |
inferred |
GenerationOptions() |
maxRetries |
inferred |
2 |
maxRepairs |
inferred |
0 |
mode |
inferred |
omAuto |
abort |
AbortCheck |
nil |
providerOptions |
inferred |
ProviderOptions() |
truncation |
inferred |
otReject |
trace |
TraceSink |
nil |
streamObjectAsync (overload 2)
Section titled “streamObjectAsync (overload 2)”Stream structured output and decode the final value into T.
proc streamObjectAsync[T](model: LanguageModel; prompt = ""; messages: seq[Message] = @[]; system = ""; name = ""; description = ""; maxTokens = 0; conversationId = ""; generationOptions = GenerationOptions(); wakeFd: cint = -1; maxRetries = 2; maxRepairs = 0; mode = omAuto; abort: AbortCheck = nil; onPartial: PartialObjectCallback = nil; onEvent: StreamCallback = nil; providerOptions = ProviderOptions(); truncation = otReject; trace: TraceSink = nil): Future[ ObjectResult[T]] {.stackTrace: false.}Type parameters: T.
Returns: Future[ObjectResult[T]].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
model |
LanguageModel |
|
prompt |
inferred |
"" |
messages |
seq[Message] |
@[] |
system |
inferred |
"" |
name |
inferred |
"" |
description |
inferred |
"" |
maxTokens |
inferred |
0 |
conversationId |
inferred |
"" |
generationOptions |
inferred |
GenerationOptions() |
wakeFd |
cint |
-1 |
maxRetries |
inferred |
2 |
maxRepairs |
inferred |
0 |
mode |
inferred |
omAuto |
abort |
AbortCheck |
nil |
onPartial |
PartialObjectCallback |
nil |
onEvent |
StreamCallback |
nil |
providerOptions |
inferred |
ProviderOptions() |
truncation |
inferred |
otReject |
trace |
TraceSink |
nil |
streamObject (overload 2)
Section titled “streamObject (overload 2)”Synchronously stream structured output and decode it into T.
proc streamObject[T](model: LanguageModel; prompt = ""; messages: seq[Message] = @[]; system = ""; name = ""; description = ""; maxTokens = 0; conversationId = ""; generationOptions = GenerationOptions(); wakeFd: cint = -1; maxRetries = 2; maxRepairs = 0; mode = omAuto; abort: AbortCheck = nil; onPartial: PartialObjectCallback = nil; onEvent: StreamCallback = nil; providerOptions = ProviderOptions(); truncation = otReject; trace: TraceSink = nil): ObjectResult[T]Type parameters: T.
Returns: ObjectResult[T].
Arguments
Section titled “Arguments”| Name | Type | Default |
|---|---|---|
model |
LanguageModel |
|
prompt |
inferred |
"" |
messages |
seq[Message] |
@[] |
system |
inferred |
"" |
name |
inferred |
"" |
description |
inferred |
"" |
maxTokens |
inferred |
0 |
conversationId |
inferred |
"" |
generationOptions |
inferred |
GenerationOptions() |
wakeFd |
cint |
-1 |
maxRetries |
inferred |
2 |
maxRepairs |
inferred |
0 |
mode |
inferred |
omAuto |
abort |
AbortCheck |
nil |
onPartial |
PartialObjectCallback |
nil |
onEvent |
StreamCallback |
nil |
providerOptions |
inferred |
ProviderOptions() |
truncation |
inferred |
otReject |
trace |
TraceSink |
nil |