# sentient-engineering/sentient architecture

> Architecture diagram of the GitHub repository sentient-engineering/sentient, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sentient-engineering/sentient
- Repository: https://github.com/sentient-engineering/sentient

## Overview

##### Project type and purpose
- This is a Python library (“sentient”) that provides browser-controlling AI agents with a single function call.
- It orchestrates prompts to an LLM, parses its structured JSON, and executes browser operations via Playwright’s remote-debugging interface.

##### File structure
- Top-level scripts and config:
- cookookbook.py, README.md, pyproject.toml, requirements.txt
- Entrypoint:
- sentient/__main__.py – handles CLI or importable `sentient.invoke`.
- Configuration:
- sentient/config/config.py – loads defaults, environment variables, API keys.
- Core engine:
- sentient/core/orchestrator/orchestrator.py – main loop and decision logic.
- sentient/core/agent/agent.py & base.py – represents a single agent instance.
- sentient/core/memory/ltm.py – long-term memory store.
- sentient/core/models/models.py – data structures for model I/O.
- sentient/core/prompts/prompts.py – prompt templates and JSON schemas.
- Skills:
- sentient/core/skills/* – each .py is a browser action (open_url, click, enter_text, screenshot, PDF extraction, etc.).
- WebDriver adapter:
- sentient/core/web_driver/playwright.py – wraps Playwright remote-debugging API.
- Utilities:
- sentient/utils/* – logging, CLI helper, DOM helpers, JSON extraction, provider registry, message typing.

##### README for additional insights
- Usage pattern: `asyncio.run(sentient.invoke(goal=…, provider=…, model=…))`.
- External dependencies:
- Remote-debugging Chrome/Brave at port 9222.
- OpenAI API (or Anthropic, Ollama, etc.) accessed via provider abstractions in utils/providers.py.
- Customization via task_instructions and .env for API keys.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External User
    User((User CLI/Import)):::ext

    %% Entrypoint and Config
    ENT["Entrypoint\nsentient.invoke"]:::core
    Config["Configuration Loader"]:::util

    %% Core Runtime
    Orch["Orchestrator"]:::core
    Agent["Agent Instance"]:::core
    Base["Agent Base Classes"]:::core
    Memory[(Long-Term Memory Store)]:::core
    Models["Data Models for I/O"]:::core
    Prompts["Prompt Templates & Schemas"]:::core

    subgraph "Skill Executor Modules"
        direction TB
        OpenURL["open_url"]:::core
        GetURL["get_url"]:::core
        ClickSel["click_using_selector"]:::core
        EnterTextSel["enter_text_using_selector"]:::core
        EnterTextClick["enter_text_and_click"]:::core
        PressKey["press_key_combination"]:::core
        UploadFile["upload_file"]:::core
        Screenshot["get_screenshot"]:::core
        DOMContent["get_dom_with_content_type"]:::core
        PDFExtr["pdf_text_extractor"]:::core
        UserInput["get_user_input"]:::core
    end

    WD["WebDriver Adapter\n(Playwright)"]:::core

    %% External Services
    LLM((LLM API)):::ext
    Browser((Browser\nChrome/Brave)):::ext

    %% Utilities
    subgraph "Utilities & Helpers"
        direction TB
        Logger["logger"]:::util
        CLIHelper["cli_helper"]:::util
        DOMHelper["dom_helper"]:::util
        ExtractJSON["extract_json"]:::util
        MessageType["message_type"]:::util
        PydanticUtil["_pydantic"]:::util
        FuncUtils["function_utils"]:::util
        DOMObserver["dom_mutation_observer"]:::util
        Accessibility["get_detailed_accessibility_tree"]:::util
        UIMsgType["ui_messagetype"]:::util
    end

    %% Connections
    User -->|calls| ENT
    ENT -->|loads| Config
    ENT -->|init| Orch

    Orch -->|uses templates| Prompts
    Prompts -->|requests| Provider
    Provider -->|calls| LLM
    LLM -->|returns JSON| Orch

    Orch -->|stores/retrieves| Memory
    Orch -->|handles data| Models
    Orch -->|manages| Agent
    Orch -->|invokes| OpenURL
    Orch -->|invokes| GetURL
    Orch -->|invokes| ClickSel
    Orch -->|invokes| EnterTextSel
    Orch -->|invokes| EnterTextClick
    Orch -->|invokes| PressKey
    Orch -->|invokes| UploadFile
    Orch -->|invokes| Screenshot
    Orch -->|invokes| DOMContent
    Orch -->|invokes| PDFExtr
    Orch -->|invokes| UserInput

    OpenURL -->|controls| WD
    GetURL -->|controls| WD
    ClickSel -->|controls| WD
    EnterTextSel -->|controls| WD
    EnterTextClick -->|controls| WD
    PressKey -->|controls| WD
    UploadFile -->|controls| WD
    Screenshot -->|controls| WD
    DOMContent -->|controls| WD
    PDFExtr -->|controls| WD
    UserInput -->|controls| WD

    WD -->|DevTools Protocol| Browser
    Browser -->|response| WD
    WD -->|results| Orch

    %% Utilities usage
    Orch --> Logger
    Orch --> CLIHelper
    Orch --> DOMHelper
    Orch --> ExtractJSON
    Orch --> MessageType
    Orch --> PydanticUtil
    Orch --> FuncUtils
    Orch --> DOMObserver
    Orch --> Accessibility
    Orch --> UIMsgType

    %% Click Events
    click ENT "https://github.com/sentient-engineering/sentient/blob/main/sentient/__main__.py"
    click Config "https://github.com/sentient-engineering/sentient/blob/main/sentient/config/config.py"
    click Orch "https://github.com/sentient-engineering/sentient/blob/main/sentient/core/orchestrator/orchestrator.py"
    click Agent "https://github.com/sentient-engineering/sentient/blob/main/sentient/core/agent/agent.py"
    click Base "https://github.com/sentient-engineering/sentient/blob/main/sentient/core/agent/base.py"
    click Memory "https://github.com/sentient-engineering/sentient/blob/main/sentient/core/memory/ltm.py"
    click Models "https://github.com/sentient-engineering/sentient/blob/main/sentient/core/models/models.py"
    click Prompts "https://github.com/sentient-engineering/sentient/blob/main/sentient/core/prompts/prompts.py"
    click Provider "https://github.com/sentient-engineering/sentient/blob/main/sentient/utils/providers.py"
    click OpenURL "https://github.com/sentient-engineering/sentient/blob/main/sentient/core/skills/open_url.py"
    click GetURL "https://github.com/sentient-engineering/sentient/blob/main/sentient/core/skills/get_url.py"
    click ClickSel "https://github.com/sentient-engineering/sentient/blob/main/sentient/core/skills/click_using_selector.py"
    click EnterTextSel "https://github.com/sentient-engineering/sentient/blob/main/sentient/core/skills/enter_text_using_selector.py"
    click EnterTextClick "https://github.com/sentient-engineering/sentient/blob/main/sentient/core/skills/enter_text_and_click.py"
    click PressKey "https://github.com/sentient-engineering/sentient/blob/main/sentient/core/skills/press_key_combination.py"
    click UploadFile "https://github.com/sentient-engineering/sentient/blob/main/sentient/core/skills/upload_file.py"
    click Screenshot "https://github.com/sentient-engineering/sentient/blob/main/sentient/core/skills/get_screenshot.py"
    click DOMContent "https://github.com/sentient-engineering/sentient/blob/main/sentient/core/skills/get_dom_with_content_type.py"
    click PDFExtr "https://github.com/sentient-engineering/sentient/blob/main/sentient/core/skills/pdf_text_extractor.py"
    click UserInput "https://github.com/sentient-engineering/sentient/blob/main/sentient/core/skills/get_user_input.py"
    click WD "https://github.com/sentient-engineering/sentient/blob/main/sentient/core/web_driver/playwright.py"
    click Logger "https://github.com/sentient-engineering/sentient/blob/main/sentient/utils/logger.py"
    click CLIHelper "https://github.com/sentient-engineering/sentient/blob/main/sentient/utils/cli_helper.py"
    click DOMHelper "https://github.com/sentient-engineering/sentient/blob/main/sentient/utils/dom_helper.py"
    click ExtractJSON "https://github.com/sentient-engineering/sentient/blob/main/sentient/utils/extract_json.py"
    click MessageType "https://github.com/sentient-engineering/sentient/blob/main/sentient/utils/message_type.py"
    click PydanticUtil "https://github.com/sentient-engineering/sentient/blob/main/sentient/utils/_pydantic.py"
    click FuncUtils "https://github.com/sentient-engineering/sentient/blob/main/sentient/utils/function_utils.py"
    click DOMObserver "https://github.com/sentient-engineering/sentient/blob/main/sentient/utils/dom_mutation_observer.py"
    click Accessibility "https://github.com/sentient-engineering/sentient/blob/main/sentient/utils/get_detailed_accessibility_tree.py"
    click UIMsgType "https://github.com/sentient-engineering/sentient/blob/main/sentient/utils/ui_messagetype.py"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef ext fill:#90EE90,stroke:#000,stroke-width:1px
    classDef util fill:#FFFF99,stroke:#000,stroke-width:1px
```
