Oracle Agent Engine database setup and execution
This page provides the copyable Markdown source for the database-execution.md reference used by the Codex skill.
Copyable Markdown source
Copy the following block into references/database-execution.md.
# Oracle Agent Engine database setup and execution
For a generation request, return artifacts. For requested execution, establish the service, PDB and principal and run the authorized steps using SQL*Plus, SQLcl or an approved connector. Record unavailable steps as not performed.
## Preflight in the execution connection
Record deployment type (managed service or self-managed), intended credential owner and endpoint. Run these queries in the target connection. Have the DBA confirm the installed RU and SQL patch status when catalog access is restricted.
<pre class="language-sql copy"><code>select sys_context('USERENV','CON_NAME') pdb, sys_context('USERENV','SERVICE_NAME') service,
sys_context('USERENV','SESSION_USER') principal from dual;
select banner_full from v$version;
select owner, object_name, object_type, status from all_objects
where object_name in ('DBMS_AI_AGENT','DBMS_VECTOR_CHAIN')
and object_type in ('PACKAGE','PACKAGE BODY');
select owner, synonym_name, table_owner, table_name, db_link from all_synonyms
where synonym_name in ('DBMS_AI_AGENT','DBMS_VECTOR_CHAIN')
and owner in (sys_context('USERENV','CURRENT_SCHEMA'),'PUBLIC');</code></pre>
Resolve the names as the application connection sees them in the target PDB. Check the current schema first, then the applicable public synonym. Follow synonym targets to the underlying packages and confirm each owner before generating grants. If metadata visibility is restricted, ask the DBA to confirm ownership, validity and patch status. An empty result can reflect limited visibility.
<pre class="language-sql copy"><code>-- DBA in the target PDB
select patch_id, action, status, action_time from dba_registry_sqlpatch order by action_time;
-- Application connection: bind the confirmed base package owner and name.
select object_name, overload, position, argument_name, in_out, data_type
from all_arguments where owner=:agent_owner and package_name=:agent_package
order by object_name, subprogram_id, sequence;</code></pre>
This skill targets Agent Spec 26.1.0. Before execution, verify that the installed release supports the selected version, required components and public overload, including the position-zero function return.
## Application schema setup
Identify the existing application schema or, when fresh setup is authorized, have the administrator create an isolated test schema in the intended PDB. Choose authentication and available tablespaces appropriate to the deployment. Grant CREATE SESSION and only the additional privileges and quotas needed for the requested objects. Confirm tablespace names in that PDB before assigning a default or quota. Use the administrative connection for privileged setup and the application connection for Agent Engine execution. Record the container, owner, objects and configuration created by this run for targeted cleanup.
## External model setup
These examples use application principal APP_USER, OpenAI and api.openai.com. Substitute the actual values. Skip provider setup for the standalone passthrough Flow. In local model mode, `host: "local"` and `credential_name` are mutually exclusive. Use the remote provider's authentication for remote access.
**DBA in the target PDB.** Check existing grants and applicable host ACEs first. Apply only missing privileges required for this deployment. Grant CREATE CREDENTIAL only to the credential creator. For an authenticated remote provider use the privileges for the selected credential and access path in the current Get Started guide. For a cross-schema PL/SQL tool, its owner grants EXECUTE on the specific package or standalone procedure to the execution principal.
<pre class="language-sql copy"><code>select host, principal, privilege, grant_type from dba_host_aces
where principal='APP_USER';
-- SQL*Plus/SQLcl: substitute each verified package owner separately.
grant execute on &agent_owner..DBMS_AI_AGENT to APP_USER;
grant execute on &vector_owner..DBMS_VECTOR_CHAIN to APP_USER;
grant create credential to APP_USER;
begin
dbms_network_acl_admin.append_host_ace(host=>'api.openai.com',
ace=>xs$ace_type(privilege_list=>xs$name_list('http'),
principal_name=>'APP_USER', principal_type=>xs_acl.ptype_db));
end;
/</code></pre>
**Credential owner.** In the application schema check `select credential_name from user_credentials`. Reuse a suitable credential after confirming its owner and intended provider. If absent and creation is authorized, bind the selected provider's JSON from a secret manager using a driver with logging disabled, or have the administrator provision it. For OpenAI the JSON has an `access_token` field. Other providers can require different fields (see Get Started). Never request secrets in chat or put them in scripts, command arguments, substitution variables, traces or spool files.
<pre class="language-sql copy"><code>begin
dbms_vector_chain.create_credential(
credential_name=>'AI_PROVIDER_CREDENTIAL', params=>json(:provider_json));
end;
/</code></pre>
**Verify as the application principal.** Execute the requested spec on that connection. For an Agent inspect a harmless tool call, its arguments, result and final answer with the intended provider, endpoint, model and settings. An HTTP or text-only response verifies only that narrower operation.
## Choose how the spec will be run
Ask whether the user needs an immediate execution example, a named stored definition for repeated use, or both. If they have no preference, recommend an immediate example to demonstrate behavior and offer storage for repeated execution.
- **Immediate:** `DBMS_AI_AGENT.EXECUTE_IMMEDIATE` receives the Agent Spec and input JSON for that call.
- **Stored:** `DBMS_AI_AGENT.CREATE_AGENT` validates and stores the complete spec under a database name. A later `DBMS_AI_AGENT.EXECUTE_AGENT` call runs it by that stored name.
Do not conflate creating/storing an Agent with running it. When generating PL/SQL, show where the user supplies the input JSON and how the returned output JSON is read. Keep environment-specific database names, provider identifiers, credential names, and inputs clearly marked as placeholders.
## Validation and diagnosis
- Run static checks on every generated spec: parse it as JSON, then inspect version and supported components, required fields, references, input/output contracts, tool signatures, and model configuration. This is useful review, but it does not prove compatibility with the target database runtime.
- `CREATE_AGENT` validates the document structure, supported components and fields, references, graph connections, and input/output contracts before storage.
- Oracle documents no standalone validate-only operation here: `CREATE_AGENT` validates and stores the spec, while `EXECUTE_IMMEDIATE` validates and executes it. Explain these effects before presenting either as a validation step. Prefer a test database and a temporary name if the user chooses `CREATE_AGENT` for database-side validation.
- Do not call a local review “database validation.” Report database validation as not performed until the target database accepts the spec.
- Treat a runtime behavior test as a separate step. It can invoke model providers and tools, so use representative test inputs and non-production or read-only tools where possible. Run it within the requested scope and compare its output to an independent expected value.
- Offer optional trace capture when the user needs to understand which components ran and what inputs/outputs they handled. Keep trace output separate from the Agent's normal output.
- For runtime failures, check the relevant layer: spec validation, package and object privileges, provider/model compatibility, credential, ACL, PL/SQL contract, or runtime availability. Use the exact target release's diagnostic documentation.
## Evidence and reruns
Preserve the supplied spec and record its SHA-256. If the executed spec differs, retain its SHA-256 as well. List environment substitutions separately from structural corrections and tie each result to the hash actually executed.
Record effective tool-calling and structured-generation modes when applicable. Give each provider or mode configuration its own verdict. Check parameter support in the target release documentation even for names beginning with an underscore. Change settings only within the authorized scope. Prefer a session change when sufficient. For an authorized ALTER SYSTEM, record the previous value, container, scope and persistence, verify the effective value in a fresh application connection, and report the setting left in place.
Bind large specs and inputs as CLOBs or construct them from bounded chunks that respect byte limits for multibyte text. Wrapping a literal in TO_CLOB still subjects the literal to SQL or PL/SQL size limits. Identify whether a failure occurred in client transport, SQL parsing or Agent Engine execution.
Compare deterministic values exactly, including JSON types and any required ordering, whitespace or formatting. Evaluate free-form prose by meaning unless exact wording is part of the contract. Preserve meaningful differences in the recorded result.
Record spec version, service/PDB, principal, provider/model/settings, named inputs, expected and actual typed outputs, tool arguments and result, and separate registration, execution and business verdicts. A completed call can omit a line or turn the string "null" into JSON null. Preserve either mismatch as a failed assertion. Compare a direct procedure call or deterministic Flow with the same input to isolate the failing stage.
Capture database error code/message, stack and backtrace and the release-documented Agent Engine error details immediately in the same session, before another agent call. Inspect documented failure returns/statuses even without an exception. Export complete output and trace CLOBs through a driver. Restrict local artifact access and redact before sharing. A single SUBSTR or truncated console display cannot establish equality.
Use fresh names for stored agents and fixture objects. Use CREATE OR REPLACE for iterative fixture changes only after confirming from the run record that this run created that object in the same schema and PDB. Preserve existing application objects. On collision choose another name or verify the existing object and reuse it explicitly. Optional cleanup is limited to the specific objects this run created. Preserve existing agents, credentials and shared ACLs.
Diagnose by stage: check host ACE and principal for ACL denial, then DNS/proxy/TLS trust for transport errors. Check credential owner and provider format for authentication errors, and endpoint, model entitlement and tool protocol for rejected requests. Check procedure owner, directions, types and privileges for binding failures. For business mismatches compare tool arguments and outputs with the direct control. Keep the original configuration's verdict when trying alternatives. Use supported package installation and public parameters for remediation.
## Oracle documentation
- [Get Started with Oracle AI Database Agent Engine](https://docs.oracle.com/en/database/oracle/oracle-database/26/odbae/get-started-with-oracle-ai-database-agent-engine.html)
- [Create an Agent](https://docs.oracle.com/en/database/oracle/oracle-database/26/odbae/create-and-manage-agents/create-an-agent.html)
- [Execute an Agent](https://docs.oracle.com/en/database/oracle/oracle-database/26/odbae/create-and-manage-agents/execute-an-agent.html)
- [LLM Configuration and Access](https://docs.oracle.com/en/database/oracle/oracle-database/26/odbae/agent-building-blocks/llm-configuration-and-access.html)
- [Execution Tracing](https://docs.oracle.com/en/database/oracle/oracle-database/26/odbae/observability-and-diagnostics/tracing.html)
- [Agent Catalog and Runtime Statistics Views](https://docs.oracle.com/en/database/oracle/oracle-database/26/odbae/observability-and-diagnostics/agent-catalog-and-runtime-statistics-views.html)