ElGraph.Action behaviour (ElGraph v0.3.0)

Copy Markdown View Source

스키마 검증되는 작업 단위 (SPEC §4).

스키마 하나(NimbleOptions)에서 파라미터 검증과 LLM tool-calling 스펙을 동시에 생성한다 — 이것이 Action 추상화의 존재 이유다.

defmodule MyApp.SearchAction do
  use ElGraph.Action,
    name: "web_search",
    description: "웹을 검색합니다",
    schema: [query: [type: :string, required: true, doc: "검색어"]]

  @impl true
  def run(params, _context), do: {:ok, %{results: search(params.query)}}
end

use 시점에 스키마가 컴파일·검증되므로 잘못된 스키마는 컴파일 에러다. 파라미터는 atom 키와 문자열 키(LLM tool-call JSON) 맵을 모두 받는다.

그래프 노드로 쓰려면 to_node/1 — MFA를 반환하므로 durable 그래프 제약(SPEC §3.2)과 호환되며, 파라미터는 상태에서 스키마 키만 투영해 얻는다 (nil 값은 미설정으로 간주해 제외).

Summary

Functions

검증 후 모듈의 run/2를 호출한다. 검증 실패 시 run/2는 호출되지 않는다.

Action을 그래프 노드로 변환한다. MFA를 반환한다 (durable 그래프 호환).

스키마에서 LLM tool-calling 스펙을 생성한다. input_schema는 JSON Schema 맵.

파라미터(atom 또는 문자열 키 맵)를 검증하고 기본값이 적용된 atom 키 맵을 반환한다.

Callbacks

compensate(params, error, context)

(optional)
@callback compensate(params :: map(), error :: term(), context :: term()) :: :ok

run(params, context)

@callback run(params :: map(), context :: term()) :: {:ok, map()} | {:error, term()}

Functions

execute(module, params, context)

@spec execute(module(), map(), term()) :: {:ok, map()} | {:error, term()}

검증 후 모듈의 run/2를 호출한다. 검증 실패 시 run/2는 호출되지 않는다.

to_node(module)

@spec to_node(module()) :: {module(), atom(), [term()]}

Action을 그래프 노드로 변환한다. MFA를 반환한다 (durable 그래프 호환).

to_tool_spec(module)

@spec to_tool_spec(module()) :: %{
  name: String.t(),
  description: String.t(),
  input_schema: map()
}

스키마에서 LLM tool-calling 스펙을 생성한다. input_schema는 JSON Schema 맵.

validate(module, params)

@spec validate(module(), map()) :: {:ok, map()} | {:error, term()}

파라미터(atom 또는 문자열 키 맵)를 검증하고 기본값이 적용된 atom 키 맵을 반환한다.