Skip to main content

cetana

Auditable BDI agents — a cognitive architecture for the LLM era.

PyPI version License: MIT

Most LLM agents are a prompt loop: state lives in a transcript, "goals" are whatever the last completion implied, and nobody can say why the agent did what it did. The classical answer to exactly this problem is 30 years old: the Belief–Desire–Intention architecture (Bratman 1987; Rao & Georgeff 1995) — explicit mental state, deliberate commitment, coherent behaviour over time.

cetana is BDI rebuilt for LLMs, on one principle:

The architecture decides when to think. The LLM decides what to think.

  • Beliefs are a revisable, sourced, timestamped store — not lines in a prompt
  • Intentions are commitments: the agent does not re-deliberate every cycle, so behaviour is stable, cheap, and predictable
  • The LLM is consulted at exactly two points — option generation and planning — through a provider-agnostic (prompt) -> str callable
  • Plans may only use registered actions, called with arguments that fit their signatures; a hallucinated capability or argument is rejected before anything runs, not silently improvised around
  • Every cycle is recorded: agent.explain() answers "why did you do that?" with the actual cognitive history

Zero dependencies. Any LLM client. Fully deterministic under test (script the LLM, assert the behaviour).

cetanā (චේතනා) is the Pali term for volition — in Buddhist psychology, the mental factor that directs the mind toward action.

Installation

pip install cetana

Quick start

from cetana import ActionRegistry, BDIAgent, ok, fail

actions = ActionRegistry()

@actions.register("check_fridge", "See what ingredients are available")
def check_fridge():
    return ok({"rice": True, "eggs": 2})

@actions.register("cook", "Cook a named dish")
def cook(dish):
    return ok(f"{dish} ready")

# Any callable (prompt: str) -> str works: Anthropic, OpenAI, local, or a stub.
import anthropic
client = anthropic.Anthropic()
def llm(prompt):
    msg = client.messages.create(
        model="claude-opus-5-5", max_tokens=1024,
        messages=[{"role": "user", "content": prompt}],
    )
    return msg.content[0].text

agent = BDIAgent("Feed the household dinner", llm, actions)
agent.believe("time", "evening")

agent.run()

print(agent.explain())
# cycle 1:
#   options: cook_dinner: Cook rice for dinner; wait: ...
#   committed to: Cook rice for dinner — it's evening and rice is available
#   plan: check_fridge -> cook
#   executed: check_fridge({}) [ok] obs={'rice': True, 'eggs': 2}
# cycle 2:
#   executed: cook({'dish': 'rice'}) [ok] obs='rice ready'
#   intention: succeeded

The cycle

percepts ──> revise beliefs ──> committed? ──yes──> execute next step ──> observe
                                   │ no                                     │
                                   └─> deliberate (LLM) ─> commit intention ┘

Deterministic architecture code does perception, belief revision, commitment bookkeeping, execution, and failure accounting. The LLM fills two cognitive gaps — what is worth pursuing? and how? — and on step failure, a bounded replan (still worth it? new plan or give up?).

Why commitment matters

A prompt-loop agent reconsiders everything every turn — one odd completion and it wanders. A BDI agent deliberates, commits, and then executes until the intention succeeds, fails, or is deliberately dropped. Fewer LLM calls, stabler behaviour, and a meaningful answer to "what is the agent doing right now?": read agent.intention.

Commitment is the default, not a cage. Pass reconsider to decide when new percepts should break it:

def reconsider(intention, percepts):
    return percepts.get("guests_cancelled", False)

agent = BDIAgent("Feed the household dinner", llm, actions, reconsider=reconsider)

It is plain Python, so when to reconsider stays an architectural decision you can test, rather than something the LLM is asked every cycle.

When things go wrong

What happens What the agent does
An action raises, or returns something other than ok() / fail() The step fails with the error as its observation, and the agent replans
A plan names an unknown action, or arguments the action doesn't accept DeliberationError (while replanning: the intention fails)
The LLM's reply is not a JSON object of the expected shape DeliberationError
The replanner gives up, or returns an empty plan The intention is dropped, never marked achieved
Replans run out (max_replans) The intention fails

Every one of these is recorded in the trace, so agent.explain() shows it.

Testing your agent

The LLM port makes agents deterministic under test:

class ScriptedLLM:
    def __init__(self, *responses):
        self.responses = list(responses)
    def __call__(self, prompt):
        return self.responses.pop(0)

Script deliberation, assert on agent.trace — no API key, no flakiness. This library's own test suite works exactly this way.

Status & roadmap

Early release (0.2.0) — the core loop, belief store, commitment machinery, trace, and failure handling are complete and tested. Planned: belief decay and confidence-weighted revision, multiple concurrent intentions with priority scheduling, a structured-output deliberation mode, and provider extras. The design is discussed in my Artificial Cognitive Systems series on Medium.

License

MIT — see LICENSE.

Author

Ravindu Pabasara Karunarathna — also the author of tokscope, slnic, and sinhaladate.

Metadata

Release files for cetana 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cetana 0.2.0
File Size Uploaded Provenance Actions
cetana-0.2.0.tar.gz 20.0 kB Without provenance Details for cetana-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cetana 0.2.0
File Interpreter ABI Platform Actions
cetana-0.2.0-py3-none-any.whl Python 3 none any Details for cetana-0.2.0-py3-none-any.whl

Total release size: 36.8 kB

Release files / cetana-0.2.0.tar.gz

Download URL cetana-0.2.0.tar.gz
Size 20.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b8280032c323e21ac70b855ec2757896655880952ea2b5e44d8b885c8412fa94
BLAKE2b-256 checksum
How to use checksums
f7a7cb9b8b3d6c0cdb306a85c2ba4e86a35b6444ee2c59f0643394a72a449b4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.2

Release files / cetana-0.2.0-py3-none-any.whl

Download URL cetana-0.2.0-py3-none-any.whl
Size 16.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dd708e53028a92418d27e37636d9f798e8d02dcce9490950876bde6913df806f
BLAKE2b-256 checksum
How to use checksums
d9c62c0c2bcf0967d47e197f01027f7e002c2a369948adb2036a0463547d06e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.2

Security for cetana 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page