Skip to content
Navigation

Modular prompt composition components. A Neuron is a composable unit that produces a prompt fragment from context, ordered by priority.

Module Path

python
from orbiter.context.neuron import Neuron, neuron_registry

neuron_registry

python
neuron_registry: Registry[Neuron]

Global registry mapping names to Neuron instances. Built-in registrations:

NameClassPriorityDescription
"system"SystemNeuron100Date, time, platform info
"task"TaskNeuron1Task ID, input, output, plan
"history"HistoryNeuron10Windowed conversation history
"todo"TodoNeuron2Todo/checklist items
"knowledge"KnowledgeNeuron20Knowledge base snippets
"workspace"WorkspaceNeuron30Workspace artifact summaries
"skill"SkillNeuron40Available skill descriptions
"fact"FactNeuron50Extracted facts
"entity"EntityNeuron60Named entities

Neuron (ABC)

Abstract base for prompt neurons. Subclasses implement format() to produce a prompt fragment from the given context.

Constructor

python
Neuron(name: str, *, priority: int = 50)
ParameterTypeDefaultDescription
namestr(required)Human-readable name for registry and debugging
priorityint50Ordering priority (lower = earlier in prompt)

Properties

PropertyTypeDescription
namestrThe neuron name
priorityintOrdering priority

Abstract Methods

format()

python
async def format(self, ctx: Context, **kwargs: Any) -> str

Produce a prompt fragment from ctx. Returns an empty string to signal “nothing to contribute”.

ParameterTypeDescription
ctxContextThe context to extract prompt data from
**kwargsAnyExtra arguments passed via PromptBuilder.add()

Returns: A prompt fragment string.


Built-in Neurons

SystemNeuron

Provides dynamic system variables: date, time, platform. Priority 100 (low, appended near the end).

python
SystemNeuron(name: str = "system", *, priority: int = 100)

Output format:

xml
<system_info>
Current date: 2025-01-15
Current time: 14:30:00 UTC
Platform: Linux 6.1.0
</system_info>

Reads from state: Nothing (uses system clock and platform).

TaskNeuron

Provides task context: task ID, input, output, subtask plan. Priority 1 (highest, appears first).

python
TaskNeuron(name: str = "task", *, priority: int = 1)

Reads from state:

KeyTypeDescription
task_inputstrCurrent task input text
task_outputstrPartial output so far
subtaskslist[str]List of subtask descriptions (plan)

Output format:

xml
<task_info>
Task ID: task-123
Input: Write a sorting function
Plan:
  <step1>Research algorithms</step1>
  <step2>Implement quicksort</step2>
</task_info>

HistoryNeuron

Provides windowed conversation history. Priority 10.

python
HistoryNeuron(name: str = "history", *, priority: int = 10)

Reads from state:

KeyTypeDescription
historylist[dict[str, Any]]Message dicts with role and content keys

Uses ctx.config.history_rounds to limit rounds (each round = 2 messages).

Output format:

xml
<conversation_history>
[user]: What is Python?
[assistant]: Python is a programming language.
</conversation_history>

TodoNeuron

Provides todo/checklist items. Priority 2.

python
TodoNeuron(name: str = "todo", *, priority: int = 2)

Reads from state:

KeyTypeDescription
todoslist[dict[str, Any]]Dicts with item (str) and optional done (bool) keys

Output format:

xml
<todo_list>
  [x] Research algorithms
  [ ] Implement solution
</todo_list>

KnowledgeNeuron

Provides knowledge base snippets. Priority 20.

python
KnowledgeNeuron(name: str = "knowledge", *, priority: int = 20)

Reads from state:

KeyTypeDescription
knowledge_itemslist[dict[str, str]]Dicts with source and content keys

WorkspaceNeuron

Provides workspace artifact summaries. Priority 30.

python
WorkspaceNeuron(name: str = "workspace", *, priority: int = 30)

Reads from state:

KeyTypeDescription
workspace_artifactslist[dict[str, Any]]Dicts with name, optional type and size keys

SkillNeuron

Provides available skill descriptions. Priority 40.

python
SkillNeuron(name: str = "skill", *, priority: int = 40)

Reads from state:

KeyTypeDescription
skillslist[dict[str, Any]]Dicts with name, description, and optional active (bool) keys

FactNeuron

Provides extracted facts. Priority 50.

python
FactNeuron(name: str = "fact", *, priority: int = 50)

Reads from state:

KeyTypeDescription
factslist[str]List of fact strings

EntityNeuron

Provides named entities. Priority 60.

python
EntityNeuron(name: str = "entity", *, priority: int = 60)

Reads from state:

KeyTypeDescription
entitieslist[dict[str, str]]Dicts with name and type keys

Custom Neuron Example

python
from orbiter.context.neuron import Neuron, neuron_registry
from orbiter.context.context import Context

class WeatherNeuron(Neuron):
    def __init__(self):
        super().__init__("weather", priority=70)

    async def format(self, ctx: Context, **kwargs) -> str:
        weather = ctx.state.get("weather")
        if not weather:
            return ""
        return f"<weather>Current weather: {weather}</weather>"

# Register it
neuron_registry.register("weather", WeatherNeuron())

# Use with PromptBuilder
builder = PromptBuilder(ctx)
builder.add("task").add("weather").add("system")
prompt = await builder.build()