# `Condukt.Plug`
[🔗](https://github.com/tuist/condukt/blob/1.4.1/lib/condukt/plug.ex#L1)

Exposes Condukt agents and typed operations as HTTP routes.

`Condukt.Plug` is a regular Plug that runs either a statically declared
`Condukt.Operation` or a module-defined one-shot agent.

    post "/review-pr",
      to: Condukt.Plug,
      init_opts: [
        agent: MyApp.ReviewAgent,
        operation: :review_pr,
        run_opts: [timeout: 120_000]
      ]

Agent routes omit `:operation`. The request body can be a raw prompt string,
a JSON string, or a JSON object with an optional `"prompt"` string. If no
prompt is provided, `:prompt` is used, falling back to an empty prompt.

    post "/assistant",
      to: Condukt.Plug,
      init_opts: [
        agent: MyApp.AssistantAgent,
        prompt: "Help with this request.",
        run_opts: [timeout: 120_000]
      ]

Operation route request bodies must be JSON objects. Agent route request
bodies can be raw text prompts, JSON strings, or JSON objects. If
`Plug.Parsers` has already parsed the body, `conn.body_params` is reused.
Otherwise this plug reads and decodes the body itself.

Successful responses are encoded as:

    {"ok": true, "result": {...}}

Error responses are encoded as:

    {"ok": false, "error": {"code": "invalid_input", "message": "..."}}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
