# Overview

Canonical URL: https://developers.iagenify.com/sdk/ref/local-agent/
Language: en

What api.agents.create({ runtime: "local" }) returns: the agent loop as an object you hold, run, stop, inspect and rewind.

Status: 8 methods · the loop is here · read its state as it works

| Method | Does |
| --- | --- |
| [run(options)](/sdk/ref/local-agent/run) | One exchange: your message in, the answer out. |
| [stop()](/sdk/ref/local-agent/stop) | Ends the current run. |
| setMode(mode) | Changes the mode, mid-run, subagents included. |
| [compact()](/sdk/ref/local-agent/compact) | Summarises the conversation now. |
| [getHistory()](/sdk/ref/local-agent/get-history) | The conversation, in display shape. |
| [checkpoints()](/sdk/ref/local-agent/checkpoints) | Where you can go back to. |
| [rewind(n)](/sdk/ref/local-agent/rewind) | Goes back to a message. |
| [destroy()](/sdk/ref/local-agent/destroy) | Removes the session. |

```javascript
const agent = api.agents.create({ runtime: "local", machine: pc, model, memory: true });

const result = await agent.run({
  message: "Read the notes and list what is unfinished.",
  onEvent: (e) => { if (e.type === "text_delta") process.stdout.write(e.delta); },
});

console.log(agent.usage, agent.context.tokens, result.stopReason);
```

## run() is one exchange, not one task {#one-exchange}

It takes your message, loops until the model stops asking for tools, and returns. Calling it again continues the same conversation — the object holds the history.

## The object is reusable, and not concurrent {#reusable}

> **One run at a time**
>
> A second run() while one is in flight shares the same message list and the same usage counters. Await the first, or build a second agent.

## You can read its state while it works {#state}

`usage`, `context`, `todos`, `mode` and `messages` are live. An interface can poll them, or listen to [events](/sdk/agent/events), which is cheaper and more precise.

- [Properties](/sdk/ref/local-agent/properties): Everything readable.
- [run()](/sdk/ref/local-agent/run): The main method.
- [Agent engine](/sdk/agent): How the loop works.

```python
agent = api.agents.create(runtime="local", machine=pc, model=model, memory=True)

result = agent.run(
    message="Read the notes and list what is unfinished.",
    on_event=lambda e: print(e["text"]) if e["type"] == "text" else None,
)

print(agent.usage, agent.context["tokens"], result["stopReason"])
```
