Skip to main content

Results

BindAI uses AgentResult as the primary result object for completed agent execution. The result abstraction keeps application code independent from provider-specific response objects and provides a consistent way to access:
  • Execution status
  • Generated output
  • Execution error information when a failed result is returned
Streaming execution is different: streaming returns incremental provider output rather than a completed AgentResult.

AgentResult

A completed agent execution returns an AgentResult.
The public result type is:
The three application-facing fields are: For example:
For successful results, error is normally None.

Accessing the Output

The generated response is available through result.output.
For normal text generation, the output is the generated response text. For structured output, the output can instead be an instance of the requested output type. The exact Python type of output therefore depends on how the agent was executed.

Checking Execution Status

Use result.success when application behavior depends on whether execution completed successfully.
A successful result has:
A failed AgentResult has:
When a failed result contains an error message, it is available through:
Applications should not assume that every possible execution failure is converted into an AgentResult. Some execution paths can raise Python exceptions instead.

Structured Output

BindAI supports structured output through the output parameter of run(). For example:
When structured output succeeds, result.output contains the constructed output object. For example:

Structured Output Processing

The execution layer processes structured output after receiving the model response. The current execution path:
  1. Gets the model response text.
  2. Parses the response as JSON.
  3. Passes the resulting dictionary to the requested output type.
  4. Returns the constructed object when conversion succeeds.
  5. Falls back to the raw response text when conversion fails.
Conceptually:
For example, if the requested type is:
the execution layer attempts the equivalent of:
The exact construction behavior depends on the output type supplied by the application. Provider and model behavior still matters because the model must produce output that can be interpreted as the requested structure.

Structured Output Fallback

Structured-output conversion does not guarantee that the final output will always be an instance of the requested type. If JSON parsing or output construction fails, the execution layer falls back to the original response text. Therefore, applications should consider checking the output type when the distinction matters:
Applications that require strict structured output should validate the resulting object before using it as structured application data.

Inspecting Result Information

During development, inspect the result object directly:
You can also inspect the public result type:
This can be useful when developing against a specific BindAI release.

Handling Execution Failures

Agent execution can encounter failures such as:
  • Missing provider configuration
  • Invalid credentials
  • Unsupported model configuration
  • Network failures
  • Provider errors
  • Tool execution failures
  • Maximum tool iteration failures
  • Other execution errors
Applications should distinguish between a failed AgentResult and a Python exception. A failed result can be handled with:
When an execution path raises an exception, handle it normally:
For production applications, catch specific exception types when the application needs to distinguish between different failure categories.

Results and Exceptions

AgentResult and Python exceptions represent different execution outcomes. A result represents an execution path that returned an AgentResult. An exception interrupts normal execution and is handled through Python exception handling. For example:
Do not assume that every provider or execution failure will be converted into:
The exact failure behavior depends on the execution path involved.

Tool Results

Tool results are separate from the final AgentResult. A tool can return an ordinary Python value:
When the agent invokes the tool, its result becomes part of the agent execution flow. Conceptually:
The tool result is not itself the final agent result. The execution layer converts tool output into messages that are supplied back to the model when additional model execution is required. Tool execution events also expose whether the tool execution succeeded.

Tool Execution Failures

Tool failures can affect the overall agent execution. For example, the execution layer can receive a tool result containing an error and pass that information back into the model execution flow. Applications should therefore distinguish between:
  • The value returned by an individual tool.
  • The model response generated after tool execution.
  • The final AgentResult returned by the agent.
For advanced tool execution behavior, use the BindAI Tool API.

Maximum Tool Iterations

Agent execution can perform multiple model/tool turns. The agent configuration includes:
The default value is:
If execution continues beyond the configured maximum, the execution path can fail with a maximum-tool-iterations error. For example:
This setting limits repeated tool-calling cycles.

Workflow Results

Workflow execution has its own result and data flow. Workflow nodes can produce values that are passed to later nodes, and a workflow can expose its own execution result. For example:
Workflow results should be handled according to the workflow API. Do not assume that a workflow result has the same fields as AgentResult. In particular:
should not be treated as the universal result structure for every BindAI subsystem.

Result Flow

The general completed-agent result flow is:
For normal text execution:
For successful structured output:
For unsuccessful structured conversion:

Results and Structured Applications

Structured results are useful when agent output is consumed directly by application code. For example:
When structured conversion succeeds, downstream code can work with the resulting Python object instead of manually parsing generated text. Applications should still account for the possibility that structured conversion falls back to the raw response.

Results from Streaming

Streaming execution differs from standard run() execution. For example:
Streaming returns incremental output from the configured provider rather than waiting for a completed AgentResult. The streaming execution path calls the provider’s stream() method. Conceptually:
Use standard run() when the application needs a completed AgentResult. Use streaming when the application needs to process or display model output progressively.

Result Handling in Applications

A typical application can handle a completed result like this:
When the operation can raise exceptions, combine result handling with exception handling:
This keeps application-level result handling independent from provider-specific response objects.

Keeping Provider Responses Out of Application Code

One purpose of AgentResult is to provide a common application-facing result abstraction. Instead of depending directly on provider SDK response objects:
application code can work through BindAI:
This keeps provider-specific response types behind the provider abstraction. Provider and model capabilities can still affect execution behavior and available features.

Debugging Results

When debugging an agent execution, inspect the result type and values:
For structured output, inspect the output type as well:
This is useful when an application supports multiple output types or when structured conversion behavior needs to be verified.

Result Handling Best Practices

  • Use result.output to access completed agent output.
  • Check result.success when application behavior depends on successful execution.
  • Inspect result.error when a failed result is returned.
  • Handle Python exceptions separately.
  • Use structured output when downstream code requires predictable Python objects.
  • Do not assume structured conversion always succeeds.
  • Treat tool results separately from the final AgentResult.
  • Treat workflow results according to the workflow API.
  • Use streaming when incremental output is required.
  • Use run() when the application needs a completed result.
  • Keep provider-specific response handling out of application code.
  • Verify result types when supporting multiple BindAI versions or output types.
  • Test result handling against the BindAI version used by the application.

Summary

AgentResult is the primary result abstraction for completed BindAI agent execution. Its public fields are:
For normal text generation, the generated response is available through:
For structured execution, output can contain the constructed output object when JSON parsing and output-type construction succeed. If structured conversion fails in the current execution path, BindAI falls back to the raw response. A failed AgentResult can expose an error through:
but applications should also handle Python exceptions because not every execution failure necessarily becomes a failed AgentResult. Streaming is a separate execution mode and returns incremental provider output rather than a completed AgentResult. By using AgentResult instead of provider-specific response objects, applications can keep result handling consistent across supported model providers.