Quickstart

Build a support agent, ask it a question, and print its response.

Requirements

  • Python 3.10–3.14 and a local checkout of this repository.
  • Oracle Database with agent execution enabled for your user.
  • A supported model provider with an endpoint reachable from the database.
  • A database credential for the provider, if authentication is required.

For required privileges and network setup, see Oracle's Agent Engine getting started guide.

1. Install the SDK

From the repository root:

python -m venv .venv
source .venv/bin/activate
python -m pip install .

2. Configure your environment

Have your database user, password, and connection string ready. The examples use
these OpenAI settings:

SettingValue
provider"openai"
model_id"gpt-5.4"
url"https://api.openai.com/v1/chat/completions"
credential_name"OPENAI_CREDENTIAL"

Use a model available to your account and supported by your database. For other
providers, see model configuration.

3. Create a credential, if needed

If you already know the credential name, skip creation and use that name in step 4. For an endpoint that needs no authentication, skip this step and configure the model as described under llm_config().

The example below checks for OPENAI_CREDENTIAL in the connected user's schema. It reuses an existing credential and creates one only when the name is absent.
Replace the connection placeholders below. Creation requires credential-creation permission and a provider_api_key value from your application's secure
configuration; keep real passwords and API keys out of source code.

import oracledb

from oracle_db_agent_sdk import CredentialCreationError, create_api_key_credential

credential_name = "OPENAI_CREDENTIAL"
connection = oracledb.connect(
    user="<db_user>",
    password="<db_password>",
    dsn="<host>:<port>/<service_name>",
)
try:
    with connection.cursor() as cursor:
        cursor.execute(
            "SELECT 1 FROM user_credentials WHERE credential_name = :name",
            name=credential_name,
        )
        credential_exists = cursor.fetchone() is not None

    if credential_exists:
        print("Using existing credential:", credential_name)
    else:
        create_api_key_credential(
            connection=connection,
            name=credential_name,
            api_key=provider_api_key,
        )
        print("Created credential:", credential_name)
except CredentialCreationError as error:
    print("Credential creation failed:", error)
    raise
finally:
    connection.close()

create_api_key_credential() returns None on success. It stores the API key in the database; use the credential's name in llm_config(). The helper itself always
attempts creation. The existence check above is application code, using USER_CREDENTIALS for credentials owned by the connected user. Finding a name does not verify its stored key or provider access.

The check and creation are separate operations: another session can create the credential between them. CredentialCreationError covers duplicate names,
permission failures, and other creation failures, so the example reports the error and stops rather than assuming it means "already exists." Verify the cause
before retrying. Invalid helper arguments raise CredentialConfigurationError; connection and lookup failures use python-oracledb exceptions. See
credential behavior and error handling, including cleanup failures after creation.

4. Build and run an agent

This agent takes a question and asks the model to produce an answer. Use your model settings and credential name, and replace the database connection placeholders.

import oracledb

import oracle_db_agent_sdk
from oracle_db_agent_sdk import OracleDBAgentsError, agent, execute, llm_config

support_llm = llm_config(
    provider="openai",
    model_id="gpt-5.4",
    url="https://api.openai.com/v1/chat/completions",
    credential_name="OPENAI_CREDENTIAL",
)

support_agent = agent(
    name="customer_support",
    llm=support_llm,
    instruction="Answer the customer's question: {{question}}",
    inputs={"question": "string"},
    outputs={"answer": "string"},
)

connection = oracledb.connect(
    user="<db_user>",
    password="<db_password>",
    dsn="<host>:<port>/<service_name>",
)
try:
    result: oracle_db_agent_sdk.JSONValue = execute(
        connection=connection,
        workflow=support_agent,
        inputs={"question": "What details should I include in a support request?"},
    )
    print("Database response:", result)
    if isinstance(result, dict) and "answer" in result:
        print("Answer:", result["answer"])
except OracleDBAgentsError as error:
    print("Agent execution failed:", error)
    raise
finally:
    connection.close()

The except block reports SDK execution errors and re-raises them so the caller can handle the failure. The finally block closes the application-owned
connection on success or failure. Connection setup can raise python-oracledb errors before entering this block. Before retrying a workflow that uses tools,
check whether any tool already changed data; see recovery guidance.

Inspect the result

oracle_db_agent_sdk.JSONValue is a type alias provided by this SDK for ordinary JSON-compatible Python values: dictionaries, lists, strings, numbers, booleans,
or None. It describes the return value's possible types; no special response object is created.

The first print shows the full database response. The second prints result["answer"] only if the response is a dictionary containing that field.
For example, a response of {"answer": "Include your order number."} prints:

Database response: {'answer': 'Include your order number.'}
Answer: Include your order number.

execute() converts the database's JSON response to a Python value and preserves its structure. Declaring an answer output does not make the SDK extract that field or add a response wrapper. Check the returned structure before using dictionary keys or list indexes. See JSONValue for the supported value types. Change the question value to ask something else.

Next steps