Skip to main content

module cleanlab_codex.codex_tool

Tool abstraction for Cleanlab Codex.


class CodexTool

A tool that connects to a Codex project to answer questions.

method __init__

__init__(
project: 'Project',
fallback_answer: 'Optional[str]' = 'Based on the available information, I cannot provide a complete answer to this question.'
)

Initialize a CodexTool.

Args:

  • project (Project): The Codex project to use for this tool.
  • fallback_answer (str, optional): The fallback answer to use if the Codex project cannot answer the question. A default will be used if not provided.

property fallback_answer

The fallback answer to use if the Codex project cannot answer the question. This will be returned by the tool if the Codex project does not have an answer to the question.


property tool_description

The description to use for the tool when passing to an LLM. This is the description that the LLM will see when determining whether to call the tool.

Note: We recommend using the default tool description which we’ve benchmarked. Only override this if you have a specific reason.


property tool_name

The name to use for the tool when passing to an LLM. This is the name the LLM will use when determining whether to call the tool.

Note: We recommend using the default tool name which we’ve benchmarked. Only override this if you have a specific reason.


classmethod from_access_key

from_access_key(
access_key: 'str',
fallback_answer: 'Optional[str]' = 'Based on the available information, I cannot provide a complete answer to this question.'
) → CodexTool

Creates a CodexTool from an access key. The CodexTool will use the project associated with the access key provided.

Args:

  • access_key (str): The access key for the Codex project.
  • fallback_answer (str, optional): The fallback answer to use if the Codex project cannot answer the question.

Returns:

  • CodexTool: The CodexTool.

method query

query(
question: "Annotated[str, 'The query to search in the It should match the original user query unless clarification is needed (for instance to account for prior user messages), in which case changes to the query should be ']"
) → Optional[str]

Consults a database that contains answers to any possible question. If the answer is not available, this returns None.

Args:

  • question (str): The query to search in the database. It should match the original user query unless clarification is needed (for instance to account for prior user messages), in which case changes to the query should be minimal.

Returns: The answer to the question if available. If no answer is available, this returns a fallback answer or None.


method to_aws_converse_tool

to_aws_converse_tool() → Any

Converts the tool to an AWS Converse API tool.

Note: You must have the boto3 library installed (AWS SDK for Python) to use this method.


method to_langchain_tool

to_langchain_tool() → Any

Converts the tool to a LangChain tool.

Note: You must have the langchain library installed to use this method.


method to_llamaindex_tool

to_llamaindex_tool() → Any

Converts the tool to a LlamaIndex FunctionTool.

Note: You must have the llama-index library installed to use this method.


method to_openai_tool

to_openai_tool()dict[str, Any]

Converts the tool to the expected format for an OpenAI function tool. See more information on defining functions for OpenAI tool calls here.


method to_smolagents_tool

to_smolagents_tool() → Any

Converts the tool to a smolagents tool.

Note: You must have the smolagents library installed to use this method.