> ## Documentation Index
> Fetch the complete documentation index at: https://docs.niadra.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Dify

> A Dify plugin with a tool provider: the context for the prompt, the recorded reply, the three history tools and the search in the agent's notes.

The plugin in `integrations-extras/dify` in the Python SDK repository is a tool provider with six tools:

| Tool                    | What it does                                                                                                                                                                    | Who fills it |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ |
| Get context             | Records the customer's message and returns the context for the prompt: the agent's own notes (with **Agent memory** on), the customer's pack and what changed on other channels | the app      |
| Record reply            | Records the agent's reply                                                                                                                                                       | the app      |
| Search customer history | The customer's whole history, by question and period (`when`)                                                                                                                   | the model    |
| Customer timeline       | The customer's conversations and agent actions, newest first                                                                                                                    | the model    |
| Open history item       | One conversation or business object from a search or the timeline                                                                                                               | the model    |
| Search agent memory     | The agent's own working notes: procedures, tools, pitfalls; nothing about customers                                                                                             | the model    |

The customer (id type and id), the conversation id and the channel are set by the app builder, usually from the app's variables (`sys.user_id`, `sys.conversation_id`), and never by the model.

## Install

1. Build the package from the repository (`pip install dify_plugin niadra` and `dify plugin package ./dify` produce the `.difypkg`), install it in your Dify and add the provider with a Niadra source key (from the Console). The API address field stays empty; it only serves the local emulator.
2. In a chatflow: a Get context node before the LLM node (customer message = `sys.query`, conversation id = `sys.conversation_id`), its text in the LLM's system prompt after your instructions, and a Record reply node after the LLM.
3. In an agent: add the history tools; their descriptions are the same the model gets from every Niadra SDK.

## The five primitives

| Primitive    | How the plugin wires it                                                                                               |
| ------------ | --------------------------------------------------------------------------------------------------------------------- |
| Context      | Get context, with the view (`chat`, `voice`, `brief`, `full`), connected to the system prompt after your instructions |
| Turns        | Get context records the customer's message; Record reply, the agent's reply                                           |
| Tools        | Search customer history, Customer timeline, Open history item and Search agent memory, with the kit's descriptions    |
| Verification | Outside the plugin; use the SDK or the API                                                                            |
| Handoff      | Outside the plugin; use the SDK or the API                                                                            |

## Limits

* The six take the same connection fields: the customer's id type and id, the conversation id and the channel, mapped from the app's variables.
* When Niadra is slow or down, the context comes out empty and a tool says the history is unavailable; the app never stops.
* The plugin stores nothing; `PRIVACY.md` in the package lists what it sends to Niadra (the customer's handle, the conversation id, the messages of each turn and the model's queries).
* Tested with Dify's plugin SDK (`dify-plugin` 0.10.2) and Niadra on the emulator, in `integrations-extras/dify/test_niadra_plugin.py`.

## Next steps

<CardGroup cols={2}>
  <Card title="Langflow" href="/en/integrations/langflow">
    the three Langflow components.
  </Card>

  <Card title="Python SDK" href="/en/sdk/python">
    the library the plugin uses.
  </Card>
</CardGroup>
