|
| 1 | +# How NOOA runs an agent method |
| 2 | + |
| 3 | +NOOA keeps two kinds of execution in one Python class: |
| 4 | + |
| 5 | +- A method with a real body runs as regular Python. |
| 6 | +- An asynchronous method ending in `...` delegates its implementation to an |
| 7 | + LLM through a generation strategy. |
| 8 | + |
| 9 | +Agentic methods and asynchronous real-body methods are awaited. Synchronous |
| 10 | +helpers are called normally. The caller does not need a separate graph or tool |
| 11 | +invocation API: both remain ordinary Python method calls. |
| 12 | + |
| 13 | +## The call path |
| 14 | + |
| 15 | +```mermaid |
| 16 | +flowchart TD |
| 17 | + A[Python calls an agent method] --> B[Agent method wrapper] |
| 18 | + B --> C{Real body or ellipsis?} |
| 19 | + C -->|Real body| D[Run ordinary Python] |
| 20 | + C -->|Ellipsis| E[Resolve LLM, strategy, and scoped context] |
| 21 | + E --> F[Build prompt blocks and event history] |
| 22 | + F --> G{Strategy} |
| 23 | + G -->|Predict| H[Structured LLM attempt without tools] |
| 24 | + G -->|CodeAct| I[Iterative LLM and Python REPL loop] |
| 25 | + I --> J[Call visible methods and tools] |
| 26 | + J --> I |
| 27 | + H --> K[Validate return type] |
| 28 | + I --> K |
| 29 | + K -->|Invalid| L[Return validation feedback to the strategy] |
| 30 | + L --> G |
| 31 | + K -->|Valid| M[Return a Python value] |
| 32 | + D --> M |
| 33 | + B -. records .-> N[Events and nested trace spans] |
| 34 | +``` |
| 35 | + |
| 36 | +This is not a remote worker abstraction. The agent is a live Python object in |
| 37 | +the current process. CodeAct-generated Python can work with its method |
| 38 | +arguments as live objects and call the visible API on `self`. |
| 39 | + |
| 40 | +## 1. Class creation identifies agentic methods |
| 41 | + |
| 42 | +`Agent` uses a metaclass to inspect methods when the class is defined. An async |
| 43 | +method whose body ends in `...` is wrapped as an agentic method. Other methods |
| 44 | +keep their Python implementation and are wrapped only for runtime services such |
| 45 | +as tracing. |
| 46 | + |
| 47 | +```python |
| 48 | +class Analyst(Agent, llm=llm): |
| 49 | + async def classify(self, text: str) -> str: |
| 50 | + """Classify the text.""" |
| 51 | + ... # agentic |
| 52 | + |
| 53 | + def normalize(self, text: str) -> str: |
| 54 | + return text.strip().lower() # deterministic |
| 55 | +``` |
| 56 | + |
| 57 | +No tool registry or graph compiler is needed to connect these methods. The |
| 58 | +Python class is the executable definition. |
| 59 | + |
| 60 | +## 2. The runtime resolves the call configuration |
| 61 | + |
| 62 | +For an agentic method, the runtime resolves: |
| 63 | + |
| 64 | +- the LLM client, including call-, method-, instance-, class-, and parent-level |
| 65 | + overrides; |
| 66 | +- the generation strategy, defaulting to CodeAct; |
| 67 | +- method-scoped context and event-history filters; |
| 68 | +- truncation and execution settings. |
| 69 | + |
| 70 | +The built-in Predict and CodeAct strategies lock an agent instance while a |
| 71 | +generation call is active. This prevents per-instance events, history, and |
| 72 | +active generation or tool work from interleaving. CodeAct creates a fresh REPL |
| 73 | +session for each agentic call; its local variables persist only across cells |
| 74 | +within that call. Use separate agent instances for ordinary parallel fan-out. |
| 75 | + |
| 76 | +## 3. The prompt is assembled from Python structure |
| 77 | + |
| 78 | +The model receives more than the method docstring. The runtime assembles a set |
| 79 | +of named blocks: |
| 80 | + |
| 81 | +- the class role and framework instructions; |
| 82 | +- strategy instructions; |
| 83 | +- `doc(type(self))`, which describes visible methods and annotated fields; |
| 84 | +- current visible instance state; |
| 85 | +- developer context blocks; |
| 86 | +- the event history selected for this call; |
| 87 | +- the method name, signature, docstring, and arguments. |
| 88 | + |
| 89 | +Arguments are rendered by the strategy. They do not need to be interpolated |
| 90 | +again with `{argument}` in the docstring. |
| 91 | + |
| 92 | +See [Prompts and context](concepts/prompts-and-context.md) for where each kind of |
| 93 | +information belongs. |
| 94 | + |
| 95 | +## 4. The strategy implements the ellipsis |
| 96 | + |
| 97 | +`PredictStrategy` makes a structured model attempt and validates the response. |
| 98 | +It has no iterative tool loop, but validation failures can trigger additional |
| 99 | +provider attempts. It fits classification, extraction, and other tasks that do |
| 100 | +not need tools or code execution. |
| 101 | + |
| 102 | +`CodeActStrategy` gives the model two core actions: execute a Python cell and |
| 103 | +return a result. Its REPL state persists across cells for the duration of the |
| 104 | +method. Generated code can inspect objects with `doc()`, call methods on |
| 105 | +`self`, and use tools attached to the agent. |
| 106 | + |
| 107 | +Both strategies enforce the declared return type. Validation errors become |
| 108 | +feedback for another attempt instead of leaking an invalid value to the |
| 109 | +caller. |
| 110 | + |
| 111 | +## 5. Events preserve the agent's working history |
| 112 | + |
| 113 | +Tasks, model messages, reasoning, generated-code output, errors, feedback, and |
| 114 | +summaries are recorded as events. That history supplies the conversational |
| 115 | +part of later prompts and can be filtered or summarized. |
| 116 | + |
| 117 | +Context blocks and events serve different purposes: |
| 118 | + |
| 119 | +- Context blocks are named information deliberately inserted into the prompt. |
| 120 | +- Events are the chronological record of what happened. |
| 121 | + |
| 122 | +Both belong to one agent instance. A child agent begins with its own context |
| 123 | +and history unless the application passes information explicitly. |
| 124 | + |
| 125 | +## 6. Tracing records the complete call tree |
| 126 | + |
| 127 | +Tracing follows Python nesting rather than capturing only an LLM transcript. A |
| 128 | +typical trace looks like: |
| 129 | + |
| 130 | +```text |
| 131 | +method.run |
| 132 | +└── method.research |
| 133 | + └── generation |
| 134 | + ├── litellm.acompletion |
| 135 | + ├── code_execution |
| 136 | + └── method_call.search |
| 137 | +``` |
| 138 | + |
| 139 | +This makes deterministic orchestration, generated code, nested agent calls, |
| 140 | +and external tools visible in one timeline. See [Tracing](concepts/tracing.md). |
| 141 | + |
| 142 | +## What remains ordinary Python |
| 143 | + |
| 144 | +NOOA intentionally leaves application architecture in the language: |
| 145 | + |
| 146 | +- use `if`, `for`, exceptions, and `asyncio` for control flow; |
| 147 | +- use Pydantic and validators for local data contracts; |
| 148 | +- use tests for deterministic helpers and orchestrators; |
| 149 | +- use separate objects when work needs isolated state; |
| 150 | +- use operating-system isolation when generated code is allowed to execute. |
| 151 | + |
| 152 | +That boundary is the central design choice: the LLM supplies judgment inside |
| 153 | +selected methods, while Python retains control over program structure and |
| 154 | +acceptance criteria. |
| 155 | + |
| 156 | +## Continue |
| 157 | + |
| 158 | +- [Agents and methods](concepts/agents-and-methods.md) |
| 159 | +- [Strategies](concepts/strategies.md) |
| 160 | +- [Orchestration](concepts/orchestration.md) |
| 161 | +- [Framework tour](tour.md) |
0 commit comments