View Image Tool Provider
The ViewImageToolProvider allows agents to view images from their execution environment.
ViewImageToolProvider
stirrup.tools.view_image.ViewImageToolProvider
ViewImageToolProvider(
exec_env: CodeExecToolProvider | None = None,
*,
name: str = "view_image",
description: str | None = None,
)
Bases: ToolProvider
Tool provider for viewing images from an execution environment.
Can be used with an explicit exec_env or will auto-detect from the Agent's session state. Works regardless of tool ordering in the Agent.
Examples:
from stirrup.clients.chat_completions_client import ChatCompletionsClient
client = ChatCompletionsClient(model="gpt-5")
Explicit exec_env
exec_env = LocalCodeExecToolProvider() agent = Agent( client=client, name="assistant", tools=[exec_env, ViewImageToolProvider(exec_env)], )
Auto-detect (any order works)
agent = Agent( client=client, name="assistant", tools=[ViewImageToolProvider(), LocalCodeExecToolProvider()], )
Initialize ViewImageToolProvider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exec_env
|
CodeExecToolProvider | None
|
Optional execution environment. If None, will auto-detect from the Agent's session state. |
None
|
name
|
str
|
Tool name (default: "view_image"). |
'view_image'
|
description
|
str | None
|
Tool description (default: standard description). |
None
|
Source code in src/stirrup/tools/view_image.py
__aenter__
async
__aenter__() -> Tool[ViewImageParams, ToolUseCountMetadata]
Enter async context: resolve exec_env and return view_image tool.
Source code in src/stirrup/tools/view_image.py
Usage
from stirrup import Agent
from stirrup.clients.chat_completions_client import ChatCompletionsClient
from stirrup.tools import LocalCodeExecToolProvider, ViewImageToolProvider
client = ChatCompletionsClient(model="gpt-5")
agent = Agent(
client=client,
name="image_viewer",
tools=[
LocalCodeExecToolProvider(),
ViewImageToolProvider(), # Auto-detects exec environment
],
)
async with agent.session() as session:
await session.run("Create a chart with matplotlib and view it")
How It Works
- The
ViewImageToolProvideris initialized with an optionalexec_envparameter - If not provided, it automatically detects the execution environment from the session
- The
view_imagetool reads image files from the execution environment - Images are returned as
ImageContentBlockobjects for the model to see