> For the complete documentation index, see [llms.txt](https://weavescope.gitbook.io/beam_weaver/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://weavescope.gitbook.io/beam_weaver/data-and-retrieval/core.md).

# Core

BeamWeaver core defines the structs and behaviours shared by providers and the runtime.

## Values

* `BeamWeaver.Core.Message`: chat messages with roles `:system`, `:user`, `:assistant`, and `:tool`.
* `BeamWeaver.Core.Document`: text documents for retrieval and data processing.

## Behaviours

* `BeamWeaver.Core.ChatModel`
* `BeamWeaver.Core.EmbeddingModel`
* `BeamWeaver.Core.LLM`
* `BeamWeaver.Core.Tool`

Public helpers validate inputs and returned shapes before provider-specific code can claim success. Recoverable failures return tagged `BeamWeaver.Core.Error` values.

## Async

Core model wrappers expose Task-backed async helpers:

```elixir
task = BeamWeaver.Core.ChatModel.async_invoke(model, messages)
{:ok, message} = BeamWeaver.Core.Async.await(task)
```

Batch helpers return ordered task lists, so awaiting the list preserves caller input order even when work completes out of order.

## Chat History

Chat history is an explicit adapter contract. Use ETS for local/test sessions or Memory-backed sessions when history should share the same store interface as graphs and agents:

```elixir
history = BeamWeaver.Core.ChatHistory.ETS.new()
session = BeamWeaver.Core.ChatHistory.ETS.for_session(history, "thread-1")

:ok = BeamWeaver.Core.ChatHistory.add_user_message(session, "hello")
:ok = BeamWeaver.Core.ChatHistory.add_ai_message(session, "world")
{:ok, messages} = BeamWeaver.Core.ChatHistory.get_messages(session)
```

`async_get_messages/2`, `async_add_messages/3`, `async_add_message/3`, and `async_clear/2` use the same Task-backed async helpers as model wrappers.

## Related Guides

* [Messages](/beam_weaver/core-components/messages.md)
* [Tools](/beam_weaver/core-components/tools.md)
* [Models](/beam_weaver/core-components/models.md)
* [Adapters](/beam_weaver/data-and-retrieval/adapters.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://weavescope.gitbook.io/beam_weaver/data-and-retrieval/core.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
