Top-Level Modules
Standalone modules at the oats package root.
oats.date
Date/time utilities for oats.
- oats.date.naive()[source]
get naive datetime from utc
# Timezone Aware UTC
print(datetime.now(timezone.utc)) 2025-10-05 15:11:31.981400+00:00
# Return as Timezone Naive Datetime
print(datetime.now(timezone.utc).replace(tzinfo=None)) 2025-10-05 15:13:54.423262
- Return type:
- oats.date.get_third_friday_dates()[source]
Generate a list of the third Friday dates for the next 6 months. Returns dates in YYYYMMDD format, space-delimited.
oats.log
Logging utilities for oats.
- class oats.log.Lg(name='lg', colors_enabled=None, file=None)[source]
Bases:
objectA very basic logger that prints to stdout. Designed for easy monkey-patching and debugging.
disable colors with
export COLORS_ENABLED=0colors are enabled by default.- __init__(name='lg', colors_enabled=None, file=None)[source]
Initialize the logger with the given name and options.
- save(file, num_logs=10, total_len=500, is_append=False)[source]
Write the last num_logs entries to file (truncated to total_len chars).
- Return type:
- oats.log.create_log(n='lg', colors=True, file=None)[source]
Creates a logger Lg instance.
- Parameters:
name – The name of the logger (for identification in logs).
colors – enable colors in the log
file – enable saving the logs to this file
- Returns:
A Lg instance.
- oats.log.cl(n='lg', colors=True, file=None)[source]
Creates a logger Lg instance.
- Parameters:
name – The name of the logger (for identification in logs).
colors – enable colors in the log
file – enable saving the logs to this file
- Returns:
A Lg instance.
- oats.log.gl(n=None, colors=None, file=None)[source]
Initializes a global logger Lg instance - disabled by default
- Parameters:
name – The name of the logger (for identification in logs).
colors – enable colors in the log
file – enable saving the logs to this file
- Returns:
A Lg instance.
oats.models
Data models for the OAT (Open Agent Tools) system.
- class oats.models.OatPromptChoices(**data)[source]
Bases:
BaseModelContainer for tool-choice results returned by the OAT index.
- status: bool
- tool_data: dict
- version: str
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class oats.models.OatConfig(*, repo_uses_index: str = './.ai/AGENT.repo_uses.python.tools.json', repo_uses_data: dict = {}, repo_uses_actions: list = [], repo_uses_prompts: list = [], repo_uses_src_files: list = [], repo_uses_action_to_src_dict: dict = {}, repo_uses_prompt_dict: dict = {}, best_tools: list[dict] = [], best_impls: dict = {})[source]
Bases:
BaseModelConfiguration and index data for OAT tool resolution.
- repo_uses_index: str
- repo_uses_actions: list
- repo_uses_prompts: list
- repo_uses_src_files: list
- repo_uses_action_to_src_dict: dict
- repo_uses_prompt_dict: dict
- __init__(**kwargs)[source]
Load the OAT index file and build action/prompt lookup dictionaries.
- best_impls: dict
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- repo_uses_data: dict
- get_prompt_choices(prompt, verbose=False)[source]
Find tool matches for a prompt using exact and partial string matching.
- Return type:
OatPromptChoices
- get_best_matches_bm25(prompt, top_k=5, verbose=False)[source]
Use BM25 to find the best matching actions for a given prompt.
Compares the prompt against each key in repo_uses_action_to_src_dict and returns the top_k best matches sorted by BM25 score.
- Return type:
OatPromptChoices
oats.pp
Pretty-printing utilities for structured data.
oats.get_oat_config
Lazy singleton loader for the OAT (Open Agent Tools) configuration.
- oats.get_oat_config.get_oat_config()[source]
Return the process-wide OatConfig singleton, creating it on first call.
- Return type:
OatConfig
oats.setup_coder_config
Interactive CLI to generate a coder.json config file.
Prompts the user for vllm-small and t1 provider settings, then writes a new config file (default: /tmp/coder.json).
- Usage:
python setup_coder_config.py -o /path/to/output.json python setup_coder_config.py # writes to /tmp/coder.json by default
- oats.setup_coder_config.prompt(msg, default=None)[source]
Prompt the user with an optional default value.
- Return type:
- oats.setup_coder_config.ensure_v1_suffix(url)[source]
Append /v1 to the base_url if it’s missing.
- Return type:
- oats.setup_coder_config.collect_vllm_small()[source]
Collect vllm-small provider configuration from the user.
- Return type:
- oats.setup_coder_config.collect_t1()[source]
Collect t1 provider (tool-calling) configuration from the user.
- Return type:
- oats.setup_coder_config.main()[source]
CLI entry point: interactively generate a coder.json config file.
oats.agent_get_tool_choices_for_prompt
Get tool choices for a user prompt from the OAT index.
Tries exact-match lookup first, then falls back to BM25 ranking.
- oats.agent_get_tool_choices_for_prompt.agent_get_tool_choices_for_prompt(prompt, top_k=5, verbose=False)[source]
Get the best tool choices for a prompt, trying exact match then BM25.
- Return type:
OatPromptChoices
- oats.agent_get_tool_choices_for_prompt.parse_args(args=None)[source]
Parse CLI arguments for the tool-choices CLI.
- Return type:
- oats.agent_get_tool_choices_for_prompt.main(args=None)[source]
CLI entry point: look up tool choices and print JSON.
oats.call_tool_with_loader1
Call tool with loader — dynamically load tools from source and wrap them as LocalTool instances.
- class oats.call_tool_with_loader1.LocalTool[source]
Bases:
ToolA Tool whose attributes are set via setters rather than hard-coded properties.
- __init__()[source]
- property name: str
Unique identifier for the tool.
- property description: str
Description of what the tool does.
- property always_load: bool
Whether this tool should almost always be available to the model.
Mirrors Claude Code’s “alwaysLoad” concept in a lightweight way so essential tools stay visible even when we rank the broader tool set.
- property strict: bool
Whether provider-side tool schema adherence should be as strict as the serving stack supports.
- property output: str
- requires_permission(args, ctx)[source]
Check if this execution requires user permission.
Returns None if no permission needed, or a description of what permission is needed.
- async execute(args, ctx)[source]
Execute the underlying callable and return a ToolResult.
- Return type:
ToolResult
- oats.call_tool_with_loader1.load_tools_from_repo_uses_index(prompt, file_path=None, min_score=0.0, verbose=False)[source]
Import source code using get_best_tools_for_prompt(), then create a LocalTool for each matched tool.
- oats.call_tool_with_loader1.run_tool_call(prompt, tools, tool_impls, provider_id=None, api_base=None, api_key=None, model=None, verbose=False)[source]
Run a two-turn tool-call loop via LiteLLM and return the final answer.
- oats.call_tool_with_loader1.main()[source]
CLI entry point: load tools from index, wrap as LocalTool, and demo execution.
oats.determine_best_tools1
Find best tool matches from a uses schema using BM25 + optional cross-encoder reranker.
1. Pipe schema from stdin (quickest) cat schema.json | python3 determine_tool_matches.py -p “get date”
2. Pass schema file with -s python3 determine_tool_matches.py -p “utc datetime” -s my_schema.json -k 5 -w 0.1
3. With reranker for higher precision python3 determine_tool_matches.py -p “get date” -s schema.json -m bm25 -r This runs BM25 first (fast), then the cross-encoder reranks the candidates for better semantic accuracy.
# Search all Coder Tools For the Best Match
`
./oats/determine_best_tools2.py -s ./.ai/AGENT.repo_uses.python.tools.json -p 'utc'
`
- oats.determine_best_tools1.load_schema(schema_path)[source]
Load the tool-uses JSON schema from a file or stdin.
- oats.determine_best_tools1.build_corpus(uses)[source]
Build one document per (file, function) pair combining path + name + description.
- oats.determine_best_tools1.tokenize(text)[source]
Lowercase and split text into whitespace-delimited tokens.
- oats.determine_best_tools1.rank_with_bm25(query, corpus, meta, top_k, min_score)[source]
Rank corpus documents against a query using BM25 scoring.
- oats.determine_best_tools1.rank_with_tfidf(query, corpus, meta, top_k, min_score)[source]
Rank corpus documents against a query using TF-IDF + cosine similarity.
- oats.determine_best_tools1.rank_with_embeddings(query, corpus, meta, top_k, min_score, model_name)[source]
Rank corpus documents against a query using dense embeddings + cosine similarity.
- oats.determine_best_tools1.rerank(query, results, rerank_model)[source]
Rerank candidate results using a cross-encoder model.
- oats.determine_best_tools1.deduplicated(items)[source]
Return a list of unique items preserving first-seen order.
- oats.determine_best_tools1.determine_best_tools(prompt, schema, model='bm25', top_k=5, min_score=0.0, rerank=False, rerank_model='cross-encoder/ms-marco-MiniLM-L-6-v2', log_level='INFO', verbose=False)[source]
Determine the best tool matches for a given prompt.
- Return type:
- Parameters:
prompt – Search query (e.g. ‘get date’)
schema – Path to JSON schema file with ‘uses’ dict
model – Retrieval model: bm25 | tfidf | <sentence-transformer-model-name>
top_k – Number of top results
min_score – Minimum retrieval score threshold
rerank – Whether to apply cross-encoder reranker after retrieval
rerank_model – Cross-encoder model for reranking
log_level – Log level
- Returns:
query, model, reranked, best_files, best_uses, results
- Return type:
dict with keys
oats.load_tools_from_source1
Dynamically load tool functions from source files and invoke them via an LLM.
Provides utilities to: - Load public functions from .py files as OpenAI-compatible tool schemas - Auto-select the best tools for a prompt using BM25 / OAT index - Run tool-call loops with a LiteLLM-compatible model
- class oats.load_tools_from_source1.OatRepoUses(**data)[source]
Bases:
BaseModelContainer for OAT repo-level tool schema, prompts, and source file paths.
- repo_uses_tool_schema_file: str
- repo_uses_prompts: dict
- repo_uses_tool_schema: dict
- repo_src_files: list
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- oats.load_tools_from_source1.load_tools(file_paths, verbose=False)[source]
Load public functions from each .py file. Returns (TOOLS list of OpenAI schemas, TOOL_IMPLS name→callable dict).
- oats.load_tools_from_source1.run_tool_call(model, api_base, prompt, tools, tool_impls)[source]
Run a two-turn tool-call loop: LLM picks tools, we execute, LLM gives final answer.
- oats.load_tools_from_source1.get_oat_repo_uses_tools()[source]
Load and return the OAT repo tool schema, prompts, and source files.
- Return type:
OatRepoUses
- oats.load_tools_from_source1.get_best_tools_for_prompt(prompt, tool_schema=None, top_k=3, min_score=0.0, rerank=False, rerank_model='cross-encoder/ms-marco-MiniLM-L-6-v2', bm25_model='bm25', run=True, oat_enabled=True, verbose=False)[source]
Examine the prompt, determine the best tool files via determine_best_tools(), then load only those files and run the tool call.
- Return type:
- Parameters:
prompt – The user prompt.
tool_schema – Path to the JSON tool-uses index file.
top_k – Number of top candidate files to consider.
min_score – Minimum BM25/retrieval score threshold.
rerank – Whether to apply cross-encoder reranking.
rerank_model – Cross-encoder model name for reranking.
bm25_model – Retrieval model name (bm25, tfidf, or embedding model).
- oats.load_tools_from_source1.run_tool_for_prompt(prompt, model=None, api_base=None, schema=None, top_k=5, min_score=0.0, rerank=False, rerank_model='cross-encoder/ms-marco-MiniLM-L-6-v2', bm25_model='bm25', run=True)[source]
Examine the prompt, determine the best tool files via determine_best_tools(), then load only those files and run the tool call.
- Return type:
- Parameters:
model – The model identifier for litellm.
api_base – The API base URL.
prompt – The user prompt.
schema – Path to the JSON tool-uses index file.
top_k – Number of top candidate files to consider.
min_score – Minimum BM25/retrieval score threshold.
rerank – Whether to apply cross-encoder reranking.
rerank_model – Cross-encoder model name for reranking.
bm25_model – Retrieval model name (bm25, tfidf, or embedding model).
run – if False, skips running tool
- oats.load_tools_from_source1.main()[source]
CLI entry point for the dynamic tool loader.