Example

duckdb_agent.py
import json
from phi.agent.duckdb import DuckDbAgent

tables = [
    {
        "name": "movies",
        "description": "Contains information about movies from IMDB.",
        "path": "s3://phidata-public/demo_data/IMDB-Movie-Data.csv",
    },
]

duckdb_agent = DuckDbAgent(
    show_function_calls=True,
    semantic_model=json.dumps({"tables": tables}, indent=4),
)

duckdb_agent.print_response("What is the average rating of movies?")

DuckDbAgent Params

ParameterTypeDefaultDescription
namestr"DuckDbAgent"Name of the agent.
semantic_modelstrNoneSemantic model for the agent. Use this to describe the available tables, their description, data path and relations between tables.
add_chat_history_to_messagesboolTrueIf the chat history should be added to the messages.
num_history_messagesint6Number of history messages to add to the response.
followupsboolFalseIf the DuckDbAgent is allowed to run followup queries.
read_tool_call_historyboolTrueIf the DuckDbAgent is allowed to read the tool call history.
db_pathstrNonePath to the DuckDb database file.
connectionDuckDBPyConnectionNoneProvide an existing duckdb connection.
init_commandsList[str]NoneCommands ran when the duckdb connection is initialized.
read_onlyboolFalseIf the database is read-only.
configdictNoneDatabase config used to initialize the duckdb connection.
run_queriesboolTrueIf the DuckDbAgent is allowed to run queries.
inspect_queriesboolTrueIf the DuckDbAgent is allowed to inspect queries.
create_tablesboolTrueIf the DuckDbAgent is allowed to create tables.
summarize_tablesboolTrueIf the DuckDbAgent is allowed to summarize tables.
export_tablesboolTrueIf the DuckDbAgent is allowed to export tables.
base_dirPath.Where to save SQL files if needed.
save_filesboolTrueIf the DuckDbAgent is allowed to save SQL files.
read_filesboolFalseIf the DuckDbAgent is allowed to read SQL files.
list_filesboolFalseIf the DuckDbAgent is allowed to list SQL files.

Agent Reference

DuckDbAgent is a subclass of the Agent class and has access to the same params

ParameterTypeDefaultDescription
llmLLM-LLM to use for this Agent
introductionstr-Agent introduction. This is added to the chat history when a run is started.
namestr-Agent name
agent_dataDict[str, Any]-Metadata associated with this agent
run_idstr-Run UUID (autogenerated if not set)
run_namestr-Run name
run_dataDict[str, Any]-Metadata associated with this run
user_idstr-ID of the user participating in this run
user_dataDict[str, Any]-Metadata associated the user participating in this run
memoryAgentMemoryAgentMemory()Agent Memory
add_chat_history_to_messagesboolFalseAdd chat history to the messages sent to the LLM.
add_chat_history_to_promptboolFalseAdd chat history to the prompt sent to the LLM.
num_history_messagesint6Number of previous messages to add to prompt or messages sent to the LLM.
knowledge_baseAgentKnowledge-Agent Knowledge Base
add_references_to_promptboolFalseEnable RAG by adding references from the knowledge base to the prompt.
storageAgentStorage-Agent Storage
db_rowAgentRun-AgentRun from the database: DO NOT SET MANUALLY
toolsList[Union[Tool, ToolRegistry, Callable, Dict, Function]]-A list of tools provided to the LLM. Tools are functions the model may generate JSON inputs for. If you provide a dict, it is not called by the model.
show_tool_callsboolFalseShow tool calls in LLM messages.
tool_call_limitint-Maximum number of tool calls allowed.
tool_choiceUnion[str, Dict[str, Any]]-Controls which (if any) tool is called by the model. "none" means the model will not call a tool and instead generates a message. "auto" means the model can pick between generating a message or calling a tool. Specifying a particular function via {"type": "function", "function": {"name": "my_function"}} forces the model to call that tool. "none" is the default when no tools are present. "auto" is the default if tools are present.
read_chat_historyboolFalseIf True, adds a tool that allows the LLM to get the chat history.
search_knowledgeboolFalseIf True, adds a tool that allows the LLM to search the knowledge base.
update_knowledgeboolFalseIf True, adds a tool that allows the LLM to update the knowledge base.
read_tool_call_historyboolFalseIf True, adds a tool that allows the LLM to get the tool call history.
use_toolsboolFalseAllow the agent to use tools
additional_messagesList[Union[Dict, Message]]-List of additional messages added to the messages list after the system prompt. Use these for few-shot learning or to provide additional context to the LLM.
system_promptstr-Provide the system prompt as a string
system_prompt_templatePromptTemplate-Provide the system prompt as a PromptTemplate
build_default_system_promptCallable[..., Optional[str]]-If True, build a default system prompt using instructions and extra_instructions
descriptionstr-Agent description for the default system prompt
taskstr-Agent task
instructionsList[str]-List of instructions for the default system prompt
extra_instructionsList[str]-List of extra_instructions for the default system prompt Use these when you want to use the default prompt but also add some extra instructions
expected_outputstr-Expected output added to the system prompt
add_to_system_promptstr-Add a string to the end of the default system prompt
add_knowledge_base_instructionsboolTrueIf True, add instructions for using the knowledge base to the default system prompt if knowledge base is provided
prevent_hallucinationsboolFalseIf True, add instructions for letting the user know that the agent does not know the answer
prevent_prompt_injectionboolFalseIf True, add instructions to prevent prompt injection attacks
limit_tool_accessboolFalseIf True, add instructions for limiting tool access to the default system prompt if tools are provided
add_datetime_to_instructionsboolFalseIf True, add the current datetime to the prompt to give the agent a sense of time This allows for relative times like "tomorrow" to be used in the prompt
markdownboolFalseIf markdown=true, formats the output using markdown
user_promptUnion[List[Dict], str]-Provides the user prompt as a string. Note: this will ignore the input message provided to the run function
user_prompt_templatePromptTemplate-Provides the user prompt as a PromptTemplate
build_default_user_promptboolTrueIf True, build a default user prompt using references and chat history
references_functionCallable[..., Optional[str]]-Function to build references for the default user_prompt. This function, if provided, is called when add_references_to_prompt is True
references_formatLiteral['json', 'yaml']jsonFormat of the references
chat_history_functionCallable[..., Optional[str]]-Function to build the chat_history for the default user_prompt. This function, if provided, is called when add_chat_history_to_prompt is True
output_modelUnion[str, List, Type[BaseModel]]-Provide an output model for the responses
parse_outputboolTrueIf True, the output is converted into the output_model (pydantic model or json dict)
outputAny-Final LLM response i.e. the final output of this agent
save_output_to_fileStr-Save the output to a file
task_dataDict[str, Any]-Metadata associated with the agent tasks
teamList['Agent']-Agent team.
rolestr-When the agent is part of a team, this is the role of the agent in the team
add_delegation_instructionsboolTrueAdd instructions for delegating tasks to another agents
debug_modeboolFalseIf True, show debug logs
monitoringboolFalseIf True, logs Agent runs on phidata.com