API Reference¶
All public types are importable from indemnipy_ai.capabilities.excel.
from indemnipy_ai.capabilities.excel import (
ExcelCapability,
ExcelDeps,
ExcelRuntimeState,
DateParsingOptions,
WorkbookProtocol,
WorkbookTable,
WorkbookSheet,
VbaSummary,
)
ExcelCapability
dataclass
¶
Bases: AbstractCapability[ExcelDeps | Any]
Gives an agent the ability to read and analyse spreadsheets.
Attach this capability to a pydantic-ai Agent to register a set of
spreadsheet-reading tools and built-in workflow instructions. The agent can then
load local .xlsx and .xlsm files, inspect worksheets and named
tables, run DuckDB SQL queries, and store derived results that persist
across turns.
When the agent runs, for_run
checks whether the deps object
implements ExcelDeps. If it does, the existing
excel_runtime_state is reused so workbooks and derived tables from
previous turns remain available. Otherwise a fresh
ExcelRuntimeState is created for the run.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str | None
|
Capability identifier registered with the agent's toolset. |
runtime_state |
ExcelRuntimeState
|
Fallback state used when deps does not implement
|
date_parsing_options |
DateParsingOptions
|
Controls how mixed-format or ambiguous date columns are coerced when loading workbook data. |
for_run
async
¶
Prepare the capability for a run.
If deps implements ExcelDeps, the existing runtime state is reused so that workbooks and derived tables loaded in a previous turn are still available. Otherwise a fresh ExcelRuntimeState is created.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
RunContext[ExcelDeps | Any]
|
The run context. |
required |
get_toolset ¶
Get the toolset for spreadsheet capabilities.
Returns:
| Type | Description |
|---|---|
FunctionToolset
|
The toolset containing spreadsheet-related tools. |
ExcelDeps ¶
Bases: Protocol
Dependency protocol for spreadsheet capabilities.
Any object that has an excel_runtime_state attribute of type
ExcelRuntimeState
satisfies this protocol — no explicit inheritance is required.
Pass the same instance across multiple agent runs to preserve loaded workbooks and derived tables between turns in a multi-turn conversation.
Attributes:
| Name | Type | Description |
|---|---|---|
excel_runtime_state |
ExcelRuntimeState
|
Mutable state holding loaded workbooks and derived tables. |
ExcelRuntimeState
dataclass
¶
Runtime state for ExcelCapability. Holds loaded workbooks and derived tables.
Pass the same instance across multiple agent runs to preserve loaded workbooks and derived tables between turns in a multi-turn conversation.
spreadsheets
class-attribute
instance-attribute
¶
List of spreadsheets that have been loaded during the agent's execution.
workbooks
class-attribute
instance-attribute
¶
Mapping of file paths to loaded workbook instances.
derived_tables
class-attribute
instance-attribute
¶
Mapping of derived table names to their corresponding WorkbookTable instances.
DateParsingOptions
dataclass
¶
Options for parsing dates in spreadsheet data.
Attributes:
| Name | Type | Description |
|---|---|---|
parse_dates |
bool
|
When |
relaxed_about_day |
bool
|
When |
VbaSummary
dataclass
¶
Aggregates extracted VBA macros and heuristic analysis for one file.
Produced by WorkbookProtocol.vba_summary
when macros are detected
in a workbook. Use to_md to render the summary as a Markdown
document suitable for passing to an agent.
Attributes:
| Name | Type | Description |
|---|---|---|
filepath |
Path
|
Path to the workbook that was inspected. |
analysis_results |
list[_VbaAnalysisResult]
|
Heuristic findings returned by macro analysis (keyword type, keyword, and description). |
macros |
list[_VbaMacro]
|
Extracted VBA macro streams (filename, stream path, VBA filename, and source code). |
from_file
classmethod
¶
Build a summary from a workbook or OLE document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
Path
|
Path to the workbook to inspect. |
required |
Returns:
| Type | Description |
|---|---|
VbaSummary
|
A summary containing any detected analysis findings and extracted VBA macro streams. |
WorkbookProtocol ¶
Bases: Protocol
Structural protocol for a loaded workbook.
Instances are created internally and stored in
:attr:ExcelRuntimeState.workbooks <indemnipy_ai.capabilities.excel.ExcelRuntimeState.workbooks>.
You will not normally construct these directly, but you can read them after
a run to inspect what the agent loaded.
file_name
property
¶
File name without directory path.
Returns:
| Type | Description |
|---|---|
str
|
The name of the workbook file as a string. |
vba_summary
property
¶
VBA macro summary, or None if the workbook contains no macros.
Returns:
| Type | Description |
|---|---|
VbaSummary | None
|
A |
sheets
property
¶
All worksheets in the workbook.
Returns:
| Type | Description |
|---|---|
list[WorkbookSheet]
|
A list of :class: |
get_range ¶
add_table_from_range ¶
WorkbookSheet
dataclass
¶
Metadata for a single worksheet in a loaded workbook.
Returned via :attr:WorkbookProtocol.sheets. The tables list
contains only named tables. Sheets with tabular data that has not
been formally defined as a table will still appear here but with an empty
tables list; use get_range to read their raw contents.
freeze_panes
instance-attribute
¶
Freeze panes anchor cell, e.g. "B2", or None. Its presence may
indicate tabular data even without a formally defined table.
WorkbookTable
dataclass
¶
A single table extracted from a workbook, or produced by a query.
Workbook tables come from named tables or ranges registered with
add_table_from_range. Derived tables are created by
query_store_and_preview and live in
ExcelRuntimeState.derived_tables.
For both types, the dataframe attribute;
for those, sheet_name and range are empty strings.
dataframe
class-attribute
instance-attribute
¶
The table's data as a Polars DataFrame.