Condukt.Operation (Condukt v1.4.1)

Copy Markdown View Source

Typed, named entrypoints on an agent module.

An operation declares an input schema, an output schema, and a block of instructions. The macro generates a function on the agent module that validates the input, runs the operation through Condukt's structured anonymous run path, validates the output, and returns it.

Declaring

defmodule MyApp.ReviewAgent do
  use Condukt

  @impl true
  def tools, do: [Condukt.Tools.Read]

  operation :review_pr,
    input: %{
      type: "object",
      properties: %{
        repo: %{type: "string"},
        pr_number: %{type: "integer"}
      },
      required: ["repo", "pr_number"]
    },
    output: %{
      type: "object",
      properties: %{
        verdict: %{type: "string", enum: ["approve", "request_changes", "comment"]},
        summary: %{type: "string"}
      },
      required: ["verdict", "summary"]
    },
    instructions: """
    Read the PR, decide a verdict, and write a summary.
    """
end

Calling

{:ok, %{verdict: "approve", summary: _}} =
  MyApp.ReviewAgent.review_pr(%{repo: "tuist/condukt", pr_number: 1})

Each call runs without keeping history across calls.

Schemas must be JSON Schema maps. Atom keys are accepted in both schemas and call-site arguments — they are normalized internally.

Summary

Functions

Runs an operation declared on agent_module.

Functions

run(agent_module, name, args, opts \\ [])

Runs an operation declared on agent_module.

Returns {:ok, result} on success or {:error, reason} on failure. Failure reasons:

  • {:invalid_input, %JSV.ValidationError{}} — args did not match the input schema
  • {:invalid_output, %JSV.ValidationError{}} — model output did not match the output schema
  • :no_result_submitted — the agent finished without calling submit_result
  • {:unknown_operation, name} — no operation by that name on the module
  • any error returned by the underlying Condukt.Session.run/3