<!-- AUTO-GENERATED by export-skills.py — DO NOT EDIT -->
---
applyTo: '**/*.{sql,py}'
---

# oracle-fusion-ai

> Oracle Fusion Cloud AI and OCI Generative AI integration patterns. Use when connecting AI agents to Oracle ERP, HCM, SCM via REST APIs, or using Oracle's 50+ pre-built AI agents for finance, HR, and supply chain.

# Oracle Fusion Cloud AI Integration

Connect AI agents to Oracle Fusion Cloud applications (ERP, HCM, SCM) using REST APIs, and leverage Oracle's 50+ pre-built AI agents for enterprise workflows.

## When to Use

- Querying or updating Oracle Fusion Cloud data (finance, HR, supply chain) from AI agents
- Understanding Oracle's 50+ pre-built AI agents for ERP, HCM, SCM
- Integrating external LLMs (Claude, GPT, Gemini) with Oracle data via REST APIs
- Using OCI Generative AI Service with Cohere or Llama models

## Oracle's Pre-Built AI Agents (50+)

| Domain | Agents |
|---|---|
| **Finance/ERP** | Invoice processing, cash forecasting, journal anomaly detection, expense audit, financial close |
| **HCM** | Recruiting, learning recommendations, workforce planning, benefits advisor, performance review |
| **SCM** | Demand forecasting, supply chain risk, order management, inventory optimization |
| **CX** | Service agent, sales assistant |

## OCI Generative AI -- Supported Models

| Provider | Models |
|---|---|
| **Cohere** | Command R, Command R+ (Oracle's primary LLM partner) |
| **Meta** | Llama 3, Llama 3.1 (70B, 8B) |
| **Note** | No native Claude, GPT-4, or Gemini. Use API Gateway for external LLMs |

## Patterns

### 1. Oracle Fusion Cloud REST API

```python
import requests

class OracleFusionClient:
    def __init__(self, base_url: str, username: str, password: str):
        self.base_url = base_url.rstrip("/")
        self.auth = (username, password)
        self.headers = {"Content-Type": "application/json", "REST-Framework-Version": "4"}

    def _get(self, path: str, params: dict = None) -> dict:
        response = requests.get(
            f"{self.base_url}{path}",
            auth=self.auth, headers=self.headers, params=params,
        )
        response.raise_for_status()
        return response.json()

    # --- Financials ---
    def get_gl_balances(self, ledger_id: str, period: str) -> list[dict]:
        return self._get(
            "/fscmRestApi/resources/11.13.18.05/ledgerBalances",
            params={"q": f"LedgerId={ledger_id};AccountingPeriod={period}", "limit": 100},
        ).get("items", [])

    def get_invoices(self, supplier: str = "", limit: int = 25) -> list[dict]:
        params = {"limit": limit}
        if supplier:
            params["q"] = f"VendorName LIKE '{supplier}%'"
        return self._get("/fscmRestApi/resources/11.13.18.05/invoices", params).get("items", [])

    # --- HCM ---
    def search_employees(self, name: str) -> list[dict]:
        return self._get(
            "/hcmRestApi/resources/11.13.18.05/emps",
            params={"q": f"DisplayName LIKE '{name}%'", "limit": 20},
        ).get("items", [])

    def get_employee(self, person_id: str) -> dict:
        return self._get(f"/hcmRestApi/resources/11.13.18.05/emps/{person_id}")

    # --- Supply Chain ---
    def get_purchase_orders(self, status: str = "OPEN", limit: int = 25) -> list[dict]:
        return self._get(
            "/fscmRestApi/resources/11.13.18.05/purchaseOrders",
            params={"q": f"Status='{status}'", "limit": limit},
        ).get("items", [])

    def get_inventory(self, item: str, org_id: str) -> list[dict]:
        return self._get(
            "/fscmRestApi/resources/11.13.18.05/inventoryOnhand",
            params={"q": f"ItemNumber='{item}';OrganizationId={org_id}"},
        ).get("items", [])
```

### 2. OCI Generative AI Service

```python
import oci

config = oci.config.from_file()
generative_ai = oci.generative_ai_inference.GenerativeAiInferenceClient(config)

def generate_with_cohere(prompt: str) -> str:
    """Generate text using OCI Generative AI (Cohere Command R+)."""
    response = generative_ai.chat(
        oci.generative_ai_inference.models.ChatDetails(
            compartment_id="ocid1.compartment.oc1...",
            serving_mode=oci.generative_ai_inference.models.OnDemandServingMode(
                model_id="cohere.command-r-plus",
            ),
            chat_request=oci.generative_ai_inference.models.CohereChatRequest(
                message=prompt,
                max_tokens=1024,
                temperature=0.1,
            ),
        )
    )
    return response.data.chat_response.text
```

### 3. External LLM Integration via OCI API Gateway

```python
# For using Claude, GPT-4, or Gemini with Oracle data,
# route through OCI API Gateway or Oracle Integration Cloud (OIC)

import requests

def query_oracle_with_claude(question: str, oracle_data: dict) -> str:
    """Use Claude (via Bedrock or direct) to analyze Oracle data."""
    import anthropic

    client = anthropic.Anthropic()
    response = client.messages.create(
        model="claude-sonnet-4-5-20250929",
        max_tokens=1024,
        messages=[{
            "role": "user",
            "content": f"""Analyze this Oracle ERP data and answer the question.

Data: {oracle_data}

Question: {question}"""
        }],
    )
    return response.content[0].text
```

### 4. Oracle APEX AI Integration

```sql
-- Oracle APEX AI Assistant: generate SQL from natural language
-- Available in APEX 24.1+
DECLARE
    l_response CLOB;
BEGIN
    l_response := APEX_AI.GENERATE(
        p_prompt => 'List all overdue invoices over $10,000',
        p_model  => 'OCI_GENAI_COHERE',
        p_system_prompt => 'Generate Oracle SQL for the AP schema. Tables: AP_INVOICES_ALL, AP_INVOICE_LINES_ALL.'
    );
    DBMS_OUTPUT.PUT_LINE(l_response);
END;
```

## Anti-Patterns

- Using OCI GenAI exclusively when Claude/GPT are needed -- Oracle's model selection is limited
- Direct database queries bypassing Fusion REST APIs -- always use REST APIs for application data
- Hardcoding Oracle credentials -- use OCI Vault or Oracle Credential Store
- Ignoring Oracle's data security policies -- Fusion enforces row-level security via business units
- Skipping pagination -- Oracle REST APIs use offset/limit; always handle multi-page results

## References

- [Oracle Fusion Cloud REST API](https://docs.oracle.com/en/cloud/saas/applications-common/24d/farca/)
- [Oracle AI Agents](https://www.oracle.com/artificial-intelligence/ai-agents/)
- [OCI Generative AI Service](https://www.oracle.com/artificial-intelligence/generative-ai/large-language-models/)
- [Oracle APEX AI](https://apex.oracle.com/en/platform/features/ai/)
