> For the complete documentation index, see [llms.txt](https://docs.contextual.io/documentation-and-resources/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.contextual.io/documentation-and-resources/components-and-data/agents/how-agents-work/event-routing.md).

# Event Routing

Event processing Agents receive messages sent by other Agents or by Native-Object Triggers and Actions.

Often, HTTP agents are responsible for the ingres of data into your Contextual tenant and either store the incoming data into an object-type record, or send it directly to an Event Agent.

Since there can be multiple instances of a single Agent, the Contextual messaging service automatically partitions the the messages for a specific agent based on the number of agent instances that are running. Events (messages) can then be automatically allocated to a specific partition based on a "key" which is a specific property of the event. This partitioning allows you to ensure that all "related events" can be processed in the same order in which they were received, based on the partition key.

However if no partition key is specified, then messages will be randomly distributed across the available agent instances.

For example, if an event is triggered by an object-type trigger for each record update, you could use the record 'id' (primary key) as the partition key, thus ensuring that all of the events for a specific record are processed in the order in which they were triggered, even if there are many agent instances running. By using the 'id' as the partition key, all of the events for a specific record would be processed by the same agent instance, and since Event agents only process one message at a time, order of processing is ensured.

Similarly, if one agent sends a message to another agent using the "Send To Agent" node, the partition key can also be specified as a property of the node, allowing the flow developer to ensure proper processing order.


---

# 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, and the optional `goal` query parameter:

```
GET https://docs.contextual.io/documentation-and-resources/components-and-data/agents/how-agents-work/event-routing.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
