yipao.agent.core.Agent

class yipao.agent.core.Agent(llm: CustomLLM, database, vectorstore, name_collection='ddl')[source]

Agent class for managing interactions between language models and SQL databases. It uses Retrieval-Augmented Generation to construct and execute SQL queries based on natural language input.

llm

A language model for generating SQL queries.

Type:

CustomLLM

database

The database object to execute SQL queries.

vectorstore

The storage for vector embeddings of SQL statements.

retriever

A retriever for related data definitions.

Type:

VectorStoreRetriever

promptBuilder

A builder for creating SQL prompts.

Type:

PromptBuilder

history

A record of executed SQL queries.

Type:

str

__init__(llm: CustomLLM, database, vectorstore, name_collection='ddl')[source]

Initializes the Agent with a language model, database, and vector store.

Parameters:
  • llm (CustomLLM) – The language model used to generate SQL queries.

  • database – The database interface to execute SQL queries.

  • vectorstore – The vector store interface for saving SQL statement embeddings.

Methods

__init__(llm, database, vectorstore[, ...])

Initializes the Agent with a language model, database, and vector store.

document_database(database[, force_update])

Documents the database by extracting table descriptions and saving them into the vector store.

execute_sql(sql_query)

Executes an SQL query on the database.

invoke(question[, iterations, debug])

Processes a natural language question to generate and execute SQL queries over multiple iterations.