aw.util¶
Utility tools and helper functions for agents.
Includes file sampling, LLM facades, and other common utilities.
Functions
|
Get a FileStore interface to Claude Desktop's configuration. |
Compute comprehensive info about a DataFrame. |
|
Create a chat function through |
|
|
Create a text-to-text chat function using OpenAI API. |
|
Factory to create LLM function from various specifications. |
|
Get numeric columns from DataFrame. |
|
Infer pandas loader function from file extension. |
|
Infer parameters for pandas loader based on file characteristics. |
Classes
|
Tool to sample and analyze file metadata and content. |
- class aw.util.FileSamplerTool(sample_size=1024)[source]¶
Bases:
objectTool to sample and analyze file metadata and content.
Helps agents understand what kind of data they’re dealing with before attempting to load it.
Example
>>> sampler = FileSamplerTool() >>> info = sampler('/path/to/data.csv') >>> info['extension'] '.csv'
- aw.util.claude_desktop_config(key_path='mcpServers', *, config_dir=None)[source]¶
Get a FileStore interface to Claude Desktop’s configuration.
By default, operates on the ‘mcpServers’ section.
Automatically creates the config file if it doesn’t exist, and creates the mcpServers section if it’s missing.
- Parameters:
key_path – Path to nested section (default: ‘mcpServers’)
config_dir – Override default config directory location
- Returns:
FileStore interface to Claude Desktop config
Example
>>> # Add/manage MCP servers >>> mcp = claude_desktop_config() >>> >>> # Add a new server >>> mcp['download'] = { ... 'command': 'python', ... 'args': ['/path/to/agent.py'] ... } >>> >>> # List configured servers >>> list(mcp) >>> >>> # Remove a server >>> del mcp['old_server']
- aw.util.compute_dataframe_info(df)[source]¶
Compute comprehensive info about a DataFrame.
- Parameters:
df – pandas DataFrame
- Return type:
- Returns:
Dict with shape, dtypes, null counts, sample rows, etc.
Example
>>> import pandas as pd >>> df = pd.DataFrame({'a': [1, 2], 'b': [3, 4]}) >>> info = compute_dataframe_info(df) >>> info['shape'] (2, 2)
- aw.util.create_oa_chat()[source]¶
Create a chat function through
aw.llm.default_chat()(aix, elseoa).The name is kept for compatibility; generation is routed through
aix.Example
>>> chat = create_oa_chat() >>> response = chat("Hello!")
- aw.util.create_openai_chat(model='gpt-4', **default_kwargs)[source]¶
Create a text-to-text chat function using OpenAI API.
- Parameters:
model (
str) – OpenAI model name**default_kwargs – Default parameters for API calls
- Return type:
- Returns:
A callable that takes a prompt and returns a response
Example
>>> chat = create_openai_chat("gpt-4o-mini") >>> response = chat("What is 2+2?")
(Skipped: the call is billable and needs
OPENAI_API_KEY.)
- aw.util.default_llm_factory(model='gpt-4')[source]¶
Factory to create LLM function from various specifications.
- Parameters:
model (
Union[str,Callable]) – Either a model name string, or a callable- Return type:
- Returns:
A callable text-to-text function
Example
>>> llm = default_llm_factory("gpt-4") >>> llm = default_llm_factory(lambda p: f"Echo: {p}")
- aw.util.get_numeric_columns(df, exclude_nulls=True)[source]¶
Get numeric columns from DataFrame.
- Parameters:
df – pandas DataFrame
exclude_nulls (
bool) – Whether to exclude columns with null values
- Returns:
Generator of column names
Example
>>> for col in get_numeric_columns(df): ... print(col)
- aw.util.infer_loader_from_extension(extension)[source]¶
Infer pandas loader function from file extension.
- Parameters:
extension (
str) – File extension (e.g., ‘.csv’, ‘.json’)- Return type:
- Returns:
Name of pandas loader function
Example
>>> infer_loader_from_extension('.csv') 'read_csv' >>> infer_loader_from_extension('.xlsx') 'read_excel'