### Run the deterministic getting started example Source: https://github.com/agentjido/jidoka/blob/main/guides/getting-started.md Executes the local example script without requiring network access or API keys. ```bash mix run examples/getting_started/example.exs ``` -------------------------------- ### Start the Phoenix showcase application Source: https://github.com/agentjido/jidoka/blob/main/README.md Commands to initialize dependencies and start the Phoenix server for the showcase application. ```bash cd showcase mix deps.get mix phx.server ``` -------------------------------- ### Run Governed Tools Examples Source: https://github.com/agentjido/jidoka/blob/main/examples/governed_tools/README.md Commands to execute the example application, run tests, and verify Livebook documentation. ```bash mix run examples/governed_tools/example.exs mix test --only example:governed_tools mix test examples/governed_tools/test/governed_tools_test.exs --trace mix run scripts/check_livebooks.exs -- --project examples/governed_tools/governed_tools.livemd ``` -------------------------------- ### Install Browser Binary Source: https://github.com/agentjido/jidoka/blob/main/guides/browser-tools.md Run this command to install the required agent-browser binary locally. ```bash mix jido_browser.install ``` -------------------------------- ### Start an Agent Source: https://github.com/agentjido/jidoka/blob/main/guides/jido-process-integration.md Use the DSL module to start an agent under the default runtime. ```elixir {:ok, pid} = MyApp.TimeAgent.start(id: "time-agent-1") ^pid = Jidoka.whereis("time-agent-1") ``` -------------------------------- ### Install dependencies Source: https://github.com/agentjido/jidoka/blob/main/CONTRIBUTING.md Run this command to fetch the project dependencies. ```bash mix deps.get ``` -------------------------------- ### Run Jidoka Examples Source: https://github.com/agentjido/jidoka/blob/main/examples/README.md Execute specific example scripts using the mix run command. ```bash mix run examples/getting_started/example.exs mix run examples/support_agent/example.exs mix run examples/warranty_claim/example.exs mix run examples/durable_refund/example.exs mix run examples/workflow_composition/example.exs ``` -------------------------------- ### Run the Jidoka Showcase Application Source: https://github.com/agentjido/jidoka/blob/main/showcase/README.md Commands to initialize the environment and start the Phoenix server for the showcase application. ```bash cd showcase cp .env.example .env mix deps.get mix jido_browser.install agent_browser --if-missing mix phx.server ``` -------------------------------- ### Run Jidoka Example Commands Source: https://github.com/agentjido/jidoka/blob/main/examples/getting_started/README.md Execute these commands in the terminal to run the example application, verify behavior, and trace the test execution. ```bash mix run examples/getting_started/example.exs mix test --only example:getting_started mix test examples/getting_started/test/getting_started_test.exs --trace ``` -------------------------------- ### Run Example Scenarios and Livebooks Source: https://github.com/agentjido/jidoka/blob/main/showcase/README.md Commands to execute tests and verify Livebooks from the package root. ```bash mix test --only example mix run scripts/check_livebooks.exs -- --project examples/*/*.livemd ``` -------------------------------- ### Setup Notebook Environment Source: https://github.com/agentjido/jidoka/blob/main/guides/kino-notebooks.md Initializes the notebook environment and renders a status table. Use this as the first executable cell. ```elixir %{ model: model, provider: provider, live_provider?: live? } = Jidoka.Kino.setup_notebook( model: "openai:gpt-4o-mini", check_provider?: true ) ``` -------------------------------- ### Run Support Agent Demonstration Source: https://github.com/agentjido/jidoka/blob/main/examples/support_agent/README.md Executes the support agent example script using the mix task. ```bash mix run examples/support_agent/example.exs ``` -------------------------------- ### Initialize Jidoka Kino setup Source: https://github.com/agentjido/jidoka/blob/main/guides/kino-notebooks.md Configure the notebook environment for Jidoka, optionally disabling provider checks. ```elixir Jidoka.Kino.setup_notebook(model: "test:notebook-model", check_provider?: false) ``` -------------------------------- ### Start InMemory Store for Testing Source: https://github.com/agentjido/jidoka/blob/main/guides/memory.md Initialize a bounded in-memory store process for test environments. ```elixir {:ok, pid} = Jidoka.Memory.Store.InMemory.start_link([]) store = {Jidoka.Memory.Store.InMemory, pid: pid} ``` -------------------------------- ### Run Durable Refund Agent Examples Source: https://github.com/agentjido/jidoka/blob/main/examples/durable_refund/README.md Commands to execute the demonstration scripts, run tests, and verify the Livebook walkthrough. ```bash mix run examples/durable_refund/example.exs mix test --only example:durable_refund mix test examples/durable_refund/test/execution_and_continuation_test.exs --trace mix run scripts/check_livebooks.exs -- --project examples/durable_refund/durable_refund.livemd ``` -------------------------------- ### Install Jidoka via Igniter Source: https://github.com/agentjido/jidoka/blob/main/README.md Use this command if your project is already configured with Igniter. ```bash mix igniter.install jidoka@0.9.0 ``` -------------------------------- ### Run reference agents and tests Source: https://github.com/agentjido/jidoka/blob/main/README.md Commands to execute the support agent example and run specific test suites. ```bash mix run examples/support_agent/example.exs mix test --only example:support_agent mix test --only tool_calling ``` -------------------------------- ### Install Jidoka and Kino dependencies Source: https://github.com/agentjido/jidoka/blob/main/guides/kino-notebooks.md Add the required dependencies to your Livebook notebook. ```elixir Mix.install([ {:kino, "~> 0.14"}, {:jidoka, "~> 0.9.0"} ]) ``` -------------------------------- ### Run Warranty Claim Demo Commands Source: https://github.com/agentjido/jidoka/blob/main/examples/warranty_claim/README.md Commands to execute the warranty claim example script and run the associated tests. ```bash mix run examples/warranty_claim/example.exs mix test --only example:warranty_claim ``` ```bash mix test examples/warranty_claim/test/warranty_claim_triage_test.exs --trace ``` ```bash mix test --only structured_results ``` -------------------------------- ### Execution Commands Source: https://github.com/agentjido/jidoka/blob/main/examples/workflow_composition/README.md Commands to run the workflow composition example and its associated tests. ```bash mix run examples/workflow_composition/example.exs mix test --only example:workflow_composition mix test examples/workflow_composition/test/workflow_composition_test.exs --trace mix test --only bounded_dynamic_loops mix test --only static_multi_agent_workflow ``` -------------------------------- ### Start a Jidoka Session Source: https://github.com/agentjido/jidoka/blob/main/guides/sessions-and-stores.md Initializes a new session with a specified agent and optional store for persistence. ```elixir {:ok, session} = Jidoka.Session.start(MyApp.SupportAgent, session_id: "support-123", store: store, metadata: %{tenant: "acme"} ) session.session_id #=> "support-123" session.status #=> :new session.metadata #=> %{tenant: "acme"} ``` -------------------------------- ### Start or Reuse Agent Source: https://github.com/agentjido/jidoka/blob/main/guides/kino-notebooks.md Ensures an agent process is started only once per notebook session, returning the existing PID on subsequent evaluations. ```elixir {:ok, pid} = Jidoka.Kino.start_or_reuse("notebook-time-agent", fn -> MyApp.TimeAgent.start(id: "notebook-time-agent") end) ``` -------------------------------- ### Initialize and use a Jidoka session Source: https://github.com/agentjido/jidoka/blob/main/guides/sessions-and-stores.md Demonstrates starting an in-memory store and executing a chat turn within a session. ```elixir {:ok, pid} = Jidoka.Session.Store.InMemory.start_link() store = {Jidoka.Session.Store.InMemory, pid: pid} {:ok, session} = Jidoka.session(MyApp.SupportAgent, "support-123", store: store) {:ok, session, text} = Jidoka.chat(session, "Say hi to Ada.", store: store) ``` -------------------------------- ### Run standard development checks Source: https://github.com/agentjido/jidoka/blob/main/README.md Executes dependency installation, formatting checks, compilation, tests, and documentation generation. ```bash mix deps.get mix format --check-formatted mix compile --warnings-as-errors mix test mix quality mix docs --warnings-as-errors ``` -------------------------------- ### Define and Start a Jidoka Agent Source: https://github.com/agentjido/jidoka/blob/main/guides/jido-process-integration.md Defines a custom action and agent using the Jidoka DSL, then starts the agent and executes a chat turn. ```elixir defmodule MyApp.LocalTime do use Jidoka.Action, name: "local_time", description: "Returns the local time for a city.", schema: Zoi.object(%{city: Zoi.string() |> Zoi.default("Chicago")}) @impl true def run(params, _context) do city = Map.get(params, :city) || Map.get(params, "city") || "Chicago" {:ok, %{city: city, time: "09:30"}} end end defmodule MyApp.TimeAgent do use Jidoka.Agent agent :time_agent do instructions "Use local_time when asked for the time." end tools do action MyApp.LocalTime end end {:ok, _pid} = MyApp.TimeAgent.start(id: "time-agent-1") {:ok, "Chicago time is 09:30."} = Jidoka.chat("time-agent-1", "What time is it in Chicago?", llm: fake_llm()) ``` -------------------------------- ### Test Jido agents with ExUnit Source: https://github.com/agentjido/jidoka/blob/main/guides/jido-process-integration.md Demonstrates how to start a supervised Jido agent and perform a chat interaction within an ExUnit test case. ```elixir defmodule MyApp.TimeAgentTest do use ExUnit.Case, async: true setup do start_supervised!(Jidoka.Jido) id = "time-agent-#{System.unique_integer([:positive])}" start_supervised!({MyApp.TimeAgent, jido: Jidoka.Jido, id: id}) %{id: id} end test "answers the time against a hosted agent", %{id: id} do llm = fn _intent, journal, _ctx -> llm_calls = Enum.count(journal.results, fn {_id, r} -> r.kind == :llm end) case llm_calls do 0 -> {:ok, %{type: :operation, name: "local_time", arguments: %{"city" => "Chicago"}}} 1 -> {:ok, %{type: :final, content: "Chicago time is 09:30."}} end end assert {:ok, "Chicago time is 09:30."} = Jidoka.chat(id, "What time is it in Chicago?", llm: llm) end end ``` -------------------------------- ### Define Agent Configuration in YAML Source: https://github.com/agentjido/jidoka/blob/main/guides/agent-dsl.md Example of a portable agent configuration defined in YAML format. ```yaml agent: id: support_agent model: openai:gpt-4o-mini instructions: Answer support questions tersely. context: ref: support_context result: ref: support_result max_repairs: 1 tools: actions: - local_time ash_resources: - ref: account_resource actions: - read_account browsers: - name: docs mode: search allow: - docs.example.com mcp_tools: - endpoint: support_mcp prefix: support_ tools: - name: lookup_policy description: Look up support policy. controls: max_turns: 8 timeout: 30000 inputs: - control: no_secrets operations: - control: require_approval when: kind: action name: local_time outputs: - control: safe_reply ``` -------------------------------- ### Serializing and Resuming Workflow Snapshots Source: https://github.com/agentjido/jidoka/blob/main/guides/workflows.md Hibernate a loop to get a snapshot, then serialize and resume it later. ```elixir {:hibernate, snapshot} = Jidoka.Workflow.run(MyApp.QueueWorkflow, %{items: [1, 2]}) {:ok, binary} = Jidoka.Workflow.Snapshot.serialize(snapshot) {:ok, result} = Jidoka.Workflow.resume(binary, context: %{tenant: "acme"}) ``` -------------------------------- ### Define Agent Tools Source: https://github.com/agentjido/jidoka/blob/main/guides/agent-dsl.md A comprehensive example of the tools DSL block, showcasing various supported entry types. ```elixir tools do action MyApp.LocalTime ash_resource MyApp.Accounts.Customer, actions: [:read, :create] browser :docs, allow: ["https://docs.example.com"] mcp_tools endpoint: :support_mcp, prefix: "support_" skill MyApp.Skills.RefundPolicy load_path "priv/skills" workflow MyApp.Workflows.RefundQuote, as: :quote_refund subagent MyApp.EvidenceAgent, as: :collect_evidence handoff MyApp.BillingAgent, as: :billing_specialist end ``` -------------------------------- ### Runtime Configuration Overrides Source: https://github.com/agentjido/jidoka/blob/main/guides/configuration.md Uses runtime.exs to source configuration values from environment variables after release start. ```elixir # config/runtime.exs import Config if model = System.get_env("JIDOKA_DEFAULT_MODEL") do config :jidoka, default_model: model end if budget = System.get_env("JIDOKA_DEFAULT_MAX_TURNS") do config :jidoka, default_max_model_turns: String.to_integer(budget) end ``` -------------------------------- ### Standard Jidoka Invocation Styles Source: https://github.com/agentjido/jidoka/blob/main/audits/public-api/documentation-alignment-plan.md Use these primary function calls for the main developer path to ensure consistency in beginner examples. ```elixir Jidoka.chat(MyApp.Assistant, input) Jidoka.turn(MyApp.Assistant, input) Jidoka.preflight(MyApp.Assistant, input) Jidoka.inspect(MyApp.Assistant) ``` -------------------------------- ### Workflow operation metadata example Source: https://github.com/agentjido/jidoka/blob/main/guides/operation-source-contracts.md Example of the metadata map published by a workflow operation source. ```elixir %{ "source" => "workflow", "kind" => "workflow", "workflow" => "refund_review", "module" => "MyApp.Workflows.RefundReview", "timeout" => 30_000, "forward_context" => "{:only, [:tenant]}", "result" => "structured", "idempotency" => "idempotent", "parameters_schema" => %{"type" => "object", ...} } ``` -------------------------------- ### Initialize Jidoka dependencies and run tests Source: https://github.com/agentjido/jidoka/blob/main/guides/agent-spec-contract.md Use these commands to verify the environment and ensure the :jidoka test suite is functional. ```bash mix deps.get mix test ``` -------------------------------- ### Install Jidoka Dependency Source: https://github.com/agentjido/jidoka/blob/main/audits/public-api/new-developer-journey.md Add the Jidoka package to your project's dependencies. ```elixir def deps do [ {:jidoka, "~> 0.9.0"} ] end ``` -------------------------------- ### Host an agent in a process Source: https://github.com/agentjido/jidoka/blob/main/guides/public-facade.md Start, interact with, locate, and stop long-lived Jidoka agents. ```elixir {:ok, _pid} = Jidoka.start_agent(MyApp.Assistant, id: "assistant-1") {:ok, text} = Jidoka.chat("assistant-1", "Are you running?") pid = Jidoka.whereis("assistant-1") :ok = Jidoka.stop_agent("assistant-1") ``` -------------------------------- ### Compile a tool_loop plan from a minimal spec Source: https://github.com/agentjido/jidoka/blob/main/guides/agent-spec-contract.md Demonstrates how to initialize a new agent specification and compile it into a plan for testing purposes. ```elixir test "compiles a tool_loop plan from a minimal spec" do spec = Spec.new!( id: "echo", instructions: "Echo the user input.", model: "openai:gpt-4o-mini" ) assert {:ok, plan} = Jidoka.Turn.Plan.new(spec) assert plan.workflow_profile == :tool_loop assert plan.max_model_turns == Jidoka.Config.default_max_model_turns() end ``` -------------------------------- ### Cancel Session Request Source: https://github.com/agentjido/jidoka/blob/main/guides/streaming.md Asynchronously start a session turn and use Jidoka.Session.cancel/1 to stop the operation. ```elixir {:ok, request} = Jidoka.Session.chat_async(session_id, "Prepare report", store: store, stream: true ) {:ok, cancellation} = Jidoka.Session.cancel(request) {:cancelled, ^cancellation} = Jidoka.Session.await(request) ``` -------------------------------- ### Manage Session Lifecycle and Forking Source: https://github.com/agentjido/jidoka/blob/main/guides/runtime-and-harness.md Demonstrates initializing an in-memory store, running a session with checkpointing, resuming, and creating a session fork. ```elixir {:ok, pid} = Jidoka.Session.Store.InMemory.start_link() store = {Jidoka.Session.Store.InMemory, pid: pid} {:ok, session} = Jidoka.session(spec, "support-session-1", store: store) {:hibernate, session, snapshot} = Jidoka.Session.run(session.session_id, "Hello", store: store, llm: llm, checkpoint: :after_prompt ) {:ok, session, result} = Jidoka.Session.resume(session.session_id, store: store, llm: llm ) {:ok, branch} = Jidoka.Session.fork(session, session_id: "support-session-1-alternate" ) ``` -------------------------------- ### Initialize session with custom store Source: https://github.com/agentjido/jidoka/blob/main/guides/public-facade.md Configure a session with specific storage backends or runtime options. ```elixir {:ok, session} = Jidoka.session(MyApp.Assistant, "conversation-123", store: {Jidoka.Session.Store.InMemory, pid: store_pid} ) ``` -------------------------------- ### Fetch and compile dependencies Source: https://github.com/agentjido/jidoka/blob/main/guides/getting-started.md Standard commands to download and compile project dependencies. ```bash mix deps.get mix compile ``` -------------------------------- ### Declare an Idempotent Operation Source: https://github.com/agentjido/jidoka/blob/main/guides/idempotency-and-safety.md Example of defining a risky operation with an :unsafe_once idempotency policy and mandatory approval. ```elixir defmodule MyApp.SupportAgent do use Jidoka.Agent agent :support_agent do instructions "Refund only when explicitly approved." end tools do action MyApp.RefundOrder, idempotency: :unsafe_once, approval: [reason: :refund_requires_review] end end ``` -------------------------------- ### Define and Initialize an AgentView Source: https://github.com/agentjido/jidoka/blob/main/guides/agent-view.md Demonstrates defining an agent and its corresponding view, followed by initializing the view struct. ```elixir defmodule MyApp.SupportAgent do use Jidoka.Agent agent :support_agent do instructions "Answer support questions tersely." end end defmodule MyApp.SupportView do use Jidoka.AgentView, agent: MyApp.SupportAgent end {:ok, view} = MyApp.SupportView.initial(%{conversation_id: "case_123"}) view.agent_id #=> "support_agent-case_123" view.conversation_id #=> "case_123" view.runtime_context #=> %{session: "case_123"} view.status #=> :idle ``` -------------------------------- ### Inspect the prompt with preflight Source: https://github.com/agentjido/jidoka/blob/main/guides/getting-started.md Use preflight/3 to view the assembled prompt and timeline before executing the agent. ```elixir {:ok, preflight} = Jidoka.preflight(MyApp.Assistant, "What can you help me with?") preflight.prompt #=> %{ #=> model: "openai:gpt-4o-mini", #=> messages: [ #=> %{role: :system, content: "Answer clearly and briefly."}, #=> %{role: :user, content: "What can you help me with?"} #=> ], #=> operations: [], #=> result: nil, #=> memory: nil, #=> context: %{}, #=> generation: %{temperature: 0.0, max_tokens: 500}, #=> loop_index: 0 #=> } preflight.timeline #=> [ #=> %{ #=> event: :prompt_assembled, #=> phase: :assemble_prompt, #=> category: :workflow, #=> status: :completed, #=> agent_id: "assistant", #=> loop_index: 0, #=> ... #=> } #=> ] ``` -------------------------------- ### Verify project documentation and code quality Source: https://github.com/agentjido/jidoka/blob/main/guides/documentation-overview.md Execute these commands to ensure code formatting, compilation, testing, and documentation coverage meet project standards before release. ```bash mix format --check-formatted mix compile --warnings-as-errors mix test mix docs mix doctor --raise ``` -------------------------------- ### Run project test and quality commands Source: https://github.com/agentjido/jidoka/blob/main/guides/contributor-testing.md Standard commands for executing tests, checking code quality, and validating documentation. ```bash # Fast, deterministic, default. Excludes :live. mix test # Include live tests. Requires a provider key. mix test --include live # Full quality bar. mix quality # Production coverage. The minimum is 75%. mix test --cover mix test.coverage # Documentation warnings and alignment rules. mix docs --warnings-as-errors mix run scripts/check_docs.exs ``` -------------------------------- ### Perform a hibernate and resume cycle Source: https://github.com/agentjido/jidoka/blob/main/guides/snapshots-and-resume.md Demonstrates capturing a snapshot at the :after_prompt checkpoint, serializing it, and resuming the turn. ```elixir {:hibernate, snapshot} = Jidoka.turn(MyApp.SupportAgent, "Hello", checkpoint: :after_prompt ) {:ok, serialized} = Jidoka.Snapshot.serialize(snapshot) String.starts_with?(serialized, "jidoka:snapshot:v1:") #=> true {:ok, result} = Jidoka.resume(serialized) result.content ``` -------------------------------- ### Run Parity Proofs Source: https://github.com/agentjido/jidoka/blob/main/examples/README.md Execute focused provider-free parity tests for the first three feature sections. ```bash mix test --include parity test/parity ``` -------------------------------- ### Define a custom LLM capability result Source: https://github.com/agentjido/jidoka/blob/main/guides/turn-and-effect-contracts.md Example of returning typed output alongside final text in an Elixir map. ```elixir {:ok, %{ type: :final, content: "Created the image.", parts: [ Jidoka.ContentPart.text("Created the image."), Jidoka.ContentPart.image({:data, image_bytes}, media_type: "image/png") ] }} ``` -------------------------------- ### Generate an execution plan Source: https://github.com/agentjido/jidoka/blob/main/guides/public-facade.md Use Jidoka.plan/1 to retrieve the executable turn data before initiating a run. ```elixir {:ok, plan} = Jidoka.plan(MyApp.Assistant) ``` -------------------------------- ### Run Documentation Generation with Warnings Source: https://github.com/agentjido/jidoka/blob/main/audits/public-api/documentation-alignment-plan.md Executes the ExDoc documentation generator with a strict configuration that treats warnings as errors to ensure documentation quality. ```bash mix docs --warnings-as-errors ``` -------------------------------- ### Define a deterministic agent test Source: https://github.com/agentjido/jidoka/blob/main/guides/contributor-testing.md Example of a test module using a fake LLM and local operation to verify agent behavior without external API calls. ```elixir defmodule MyContributorTest do use ExUnit.Case, async: true import TestSupport defmodule TimeAgent do use Jidoka.Agent agent :contributor_time do model %{provider: :test, id: "deterministic"} instructions "Call local_time when asked for the time." end tools do local_operations do operation :local_time do description "Returns a fixed time for a city." handler fn %{"city" => city} -> {:ok, %{city: city, time: "09:30"}} end end end end end test "returns the canned answer with no provider key" do llm = operation_then_final_llm("local_time", %{"city" => "Chicago"}, "Chicago: 09:30") assert {:ok, %Jidoka.Turn.Result{content: "Chicago: 09:30"}} = Jidoka.turn(TimeAgent, "What time is it in Chicago?", llm: llm) end end ``` -------------------------------- ### Compile and Execute Model Turn Workflow Source: https://github.com/agentjido/jidoka/blob/main/guides/runic-spine-internals.md Demonstrates the minimal Runic workflow execution by compiling a plan and running it against a turn state. ```elixir alias Jidoka.Turn alias Jidoka.Adapter.Runic.TurnCompiler, as: Compiler alias Runic.Workflow spec = Jidoka.agent!(id: "spine_demo", model: %{provider: :test, id: "m"}) {:ok, plan} = Jidoka.plan(spec) workflow = Compiler.model_turn_workflow(plan) state = Turn.State.new!( spec: plan.spec, plan: plan, request: Turn.Request.new!(input: "hi"), agent_state: Jidoka.Agent.State.new!() ) workflow |> Workflow.react_until_satisfied(state) |> Workflow.raw_productions(:plan_model_effect) |> List.last() |> Map.fetch!(:pending_effects) #=> [%Jidoka.Effect.Intent{kind: :llm, ...}] ``` -------------------------------- ### Compile a Local Operation Source Source: https://github.com/agentjido/jidoka/blob/main/guides/operation-source-contracts.md Demonstrates initializing a Source.Local instance with in-process handlers and compiling it into the required agent specification and capability function. ```elixir alias Jidoka.Operation.Source {:ok, source} = Source.Local.new( operations: [ %{ name: "local_time", description: "Returns local time for a city.", handler: fn args, _ctx -> {:ok, %{city: Map.get(args, "city", "Chicago"), time: "09:30"}} end } ] ) {:ok, compiled} = Source.compile(source) compiled.operations #=> [%Jidoka.Agent.Spec.Operation{name: "local_time", ...}] compiled.capability #=> #Function<...> (operation_capability/2) ``` -------------------------------- ### Configure Jidoka application settings Source: https://github.com/agentjido/jidoka/blob/main/guides/errors-and-config-reference.md Example configuration for Jidoka settings in an Elixir config file, overriding default model, generation parameters, turn limits, and timeouts. ```elixir # config/config.exs import Config config :jidoka, default_model: "anthropic:claude-3-5-sonnet-latest", default_generation: %{params: %{temperature: 0.2, max_tokens: 1_024}}, default_max_model_turns: 6, default_turn_timeout_ms: 45_000 ``` -------------------------------- ### Perform Preflight and Inspection Tests Source: https://github.com/agentjido/jidoka/blob/main/guides/inspection-and-preflight.md Demonstrates how to verify prompt assembly and inspect agent specifications within an ExUnit test suite. ```elixir defmodule MyApp.PreflightTest do use ExUnit.Case, async: true test "assembles a prompt for the time agent" do {:ok, preflight} = Jidoka.preflight(MyApp.TimeAgent, "What time is it?") system_message = Enum.find(preflight.prompt.messages, &(&1.role == :system)) assert system_message.content =~ "Call local_time" assert Enum.find(preflight.prompt.operations, &(&1.name == "local_time")) assert preflight.diagnostics == [] end test "inspect/1 returns a tagged map" do view = Jidoka.inspect(MyApp.TimeAgent) assert view.kind == :agent assert view.spec.id == "time_agent" assert is_list(view.spec.operations) end end ``` -------------------------------- ### Run live provider tests Source: https://github.com/agentjido/jidoka/blob/main/CONTRIBUTING.md Execute live provider tests by including the specific test file in the mix test command. ```bash mix test --include live test/jidoka/live_req_llm_test.exs ``` -------------------------------- ### Perform a memory round-trip with the In-Memory store Source: https://github.com/agentjido/jidoka/blob/main/guides/memory-contracts.md Demonstrates initializing the in-memory store and executing write and recall operations using the core memory contracts. ```elixir alias Jidoka.Memory.{Entry, RecallRequest, WriteRequest, Store} {:ok, pid} = Jidoka.Memory.Store.InMemory.start_link([]) store = {Jidoka.Memory.Store.InMemory, pid: pid} entry = Entry.new!(agent_id: "time_agent", content: "User prefers Chicago time") {:ok, _write} = Store.write(store, WriteRequest.new!(entry: entry)) request = RecallRequest.new!( agent_id: "time_agent", scope: :agent, query: "preferred timezone", limit: 3 ) {:ok, recall} = Store.recall(store, request) length(recall.entries) #=> 1 ``` -------------------------------- ### Jidoka.preflight/3 Source: https://github.com/agentjido/jidoka/blob/main/README.md Assembles a prompt for an agent without executing live effects. ```APIDOC ## Jidoka.preflight(agent, input, opts \\ []) ### Description Assembles a prompt for an agent without executing live effects, useful for inspecting operations before execution. ``` -------------------------------- ### Implement Custom Memory Store Source: https://github.com/agentjido/jidoka/blob/main/guides/memory.md Create a custom storage backend by implementing the Jidoka.Memory.Store behaviour. ```elixir defmodule MyApp.MapStore do @behaviour Jidoka.Memory.Store alias Jidoka.Memory.Entry alias Jidoka.Memory.RecallRequest alias Jidoka.Memory.RecallResult alias Jidoka.Memory.WriteRequest alias Jidoka.Memory.WriteResult def start_link(_opts), do: Agent.start_link(fn -> [] end) @impl true def recall(%RecallRequest{} = request, opts) do pid = Keyword.fetch!(opts, :pid) entries = pid |> Agent.get(& &1) |> Enum.take(request.limit) RecallResult.new(request: request, entries: entries) end @impl true def write(%WriteRequest{entry: %Entry{} = entry} = request, opts) do pid = Keyword.fetch!(opts, :pid) Agent.update(pid, &[entry | &1]) WriteResult.new(request: request, entry: entry) end @impl true def list_entries(opts) do pid = Keyword.fetch!(opts, :pid) {:ok, pid |> Agent.get(& &1) |> Enum.reverse()} end end ``` -------------------------------- ### Registering Skills, Workflows, and Subagents Source: https://github.com/agentjido/jidoka/blob/main/guides/skill-workflow-subagent-tools.md Demonstrates defining a workflow and an agent that utilizes a skill, a workflow, and a subagent as tools. ```elixir defmodule MyApp.MathWorkflow do use Jidoka.Workflow workflow do id :math_workflow description "Adds one and doubles the value." input Zoi.object(%{value: Zoi.integer()}) end steps do function :calculate, {__MODULE__, :calculate, 2}, input: %{value: input(:value)} end output from(:calculate) def calculate(%{value: value}, _context), do: {:ok, %{value: (value + 1) * 2}} end defmodule MyApp.EvidenceAgent do use Jidoka.Agent agent :evidence_agent do instructions "Answer with bounded evidence." end end defmodule MyApp.HelperAgent do use Jidoka.Agent agent :helper_agent do instructions "Use available tools before answering." end tools do skill MyApp.SupportPolicySkill workflow MyApp.MathWorkflow, as: :run_math, result: :structured subagent MyApp.EvidenceAgent, as: :evidence_specialist, result: :structured end end ``` -------------------------------- ### Configure DETS Store Adapter Source: https://github.com/agentjido/jidoka/blob/main/guides/sessions-and-stores.md Initialize the single-node DETS adapter for disk-based session persistence. ```elixir {:ok, pid} = Jidoka.Session.Store.Dets.start_link( path: "/var/lib/my_app/jidoka_sessions.dets" ) store = {Jidoka.Session.Store.Dets, pid: pid} ``` -------------------------------- ### Initialize Capabilities Struct Source: https://github.com/agentjido/jidoka/blob/main/guides/runtime-capabilities-internals.md Creates a new Capabilities struct using normalized keyword options for LLM and local operations. ```elixir alias Jidoka.Runtime.Capabilities alias Jidoka.Runtime.{LocalOperations, ReqLLM} llm = ReqLLM.llm(model: "openai:gpt-4o-mini", temperature: 0.0) operations = LocalOperations.operations(%{ "local_time" => fn %{"city" => city}, _ctx -> {:ok, %{city: city, time: "09:30"}} end }) {:ok, %Capabilities{} = caps} = Capabilities.new(llm: llm, operations: operations) ``` -------------------------------- ### Snapshotting and Resuming State Source: https://github.com/agentjido/jidoka/blob/main/guides/runtime-and-harness.md Demonstrates how to hibernate a process at a specific checkpoint and resume execution using the snapshot. ```elixir {:hibernate, snapshot} = Jidoka.turn(spec, "Hello", llm: llm, checkpoint: :after_prompt ) {:ok, result} = Jidoka.resume(snapshot, llm: llm) ``` -------------------------------- ### Test Jidoka configuration helpers Source: https://github.com/agentjido/jidoka/blob/main/guides/configuration.md Use ExUnit to test configuration helpers by capturing and restoring application environment variables. Avoid async: true to prevent state leakage during environment mutation. ```elixir defmodule MyApp.JidokaConfigTest do use ExUnit.Case, async: false setup do previous_model = Application.get_env(:jidoka, :default_model) on_exit(fn -> if previous_model do Application.put_env(:jidoka, :default_model, previous_model) else Application.delete_env(:jidoka, :default_model) end end) :ok end test "model defaults are normalized through ReqLLM" do Application.put_env(:jidoka, :default_model, "openai:gpt-4o-mini") assert Jidoka.Config.model_ref(Jidoka.Config.default_model()) == "openai:gpt-4o-mini" end test "invalid positive integer raises" do assert_raise ArgumentError, ~r/invalid default_max_model_turns/, fn -> Jidoka.Config.normalize_positive_integer!(0, :default_max_model_turns) end end end ``` -------------------------------- ### Export Provider API Keys Source: https://github.com/agentjido/jidoka/blob/main/README.md Set environment variables for LLM provider authentication. ```bash export OPENAI_API_KEY=... # or export ANTHROPIC_API_KEY=... ``` -------------------------------- ### Define Source-Backed Tools Source: https://github.com/agentjido/jidoka/blob/main/guides/tools-and-operations.md Use the DSL to expose higher-level sources that compile into operations. ```elixir tools do action MyApp.Tools.LocalTime ash_resource MyApp.Accounts.User, actions: [:read] browser :docs, allow: ["docs.example.com"] end ``` -------------------------------- ### Inspect Memory Injection with Preflight Source: https://github.com/agentjido/jidoka/blob/main/guides/memory.md Verify how memory entries are injected into the prompt before executing a turn. ```elixir {:ok, preflight} = Jidoka.preflight(MyApp.MemoryAgent, "hello", memory_store: store, session_id: "conv-1" ) preflight.prompt.messages ``` -------------------------------- ### Run Scenario Tests by Tag Source: https://github.com/agentjido/jidoka/blob/main/examples/support_agent/README.md Executes specific test scenarios using ExUnit tags. ```bash mix test --only example:support_agent mix test --only tool_calling mix test --only serializable_pause_resume mix test --only input_controls mix test --only ui_projection ``` -------------------------------- ### Export provider API keys in local development Source: https://github.com/agentjido/jidoka/blob/main/guides/configuration.md Set required provider credentials directly in the shell environment for local development. ```bash export OPENAI_API_KEY=... export ANTHROPIC_API_KEY=... ``` -------------------------------- ### Project Session Replay Source: https://github.com/agentjido/jidoka/blob/main/guides/runtime-and-harness.md Creates a replay projection from a session to inspect its timeline and lineage. ```elixir {:ok, replay} = Jidoka.Session.replay(session) replay.timeline replay.lineage ``` -------------------------------- ### Execute contributor development loop Source: https://github.com/agentjido/jidoka/blob/main/guides/contributor-testing.md The standard sequence of commands for verifying changes during development. ```bash mix test path/to/test_file.exs mix format mix quality ``` -------------------------------- ### Test a local source handler Source: https://github.com/agentjido/jidoka/blob/main/guides/operation-source-contracts.md Demonstrates how to compile a local source and execute its handler using an operation intent without running a full turn. ```elixir test "local source executes its handler" do {:ok, source} = Jidoka.Operation.Source.Local.new( operations: [ %{name: "echo", handler: fn args, _ctx -> {:ok, args} end} ] ) {:ok, compiled} = Jidoka.Operation.Source.compile(source) intent = Jidoka.Effect.Intent.new(:operation, %{name: "echo", arguments: %{"value" => 42}}, idempotency: :pure ) assert {:ok, %{"value" => 42}} = compiled.capability.(intent, Jidoka.Effect.Journal.new!(), Jidoka.Context.from_data!(%{})) end ``` -------------------------------- ### Run Jidoka runtime tests Source: https://github.com/agentjido/jidoka/blob/main/guides/runtime-capabilities-internals.md Commands to fetch dependencies and execute the test suite for various runtime components. ```bash mix deps.get mix test test/jidoka/runtime/capabilities_test.exs mix test test/jidoka/runtime/req_llm_test.exs mix test test/jidoka/runtime/jido_actions_test.exs mix test test/jidoka/runtime/local_operations_test.exs ``` -------------------------------- ### Implement LLM Capability Adapter Source: https://github.com/agentjido/jidoka/blob/main/guides/runtime-capabilities-internals.md The entrypoint for an LLM adapter that returns a three-arity function for the runner. ```elixir def llm(opts \\ []) when is_list(opts) do fn %Effect.Intent{} = intent, %Effect.Journal{} = journal, _ctx -> generate(intent, journal, opts) end end ``` -------------------------------- ### Configure Jidoka application defaults Source: https://github.com/agentjido/jidoka/blob/main/guides/configuration.md Define global settings in config/config.exs to provide fallback values for agents that do not specify their own configuration. ```elixir import Config config :jidoka, default_model: "openai:gpt-4o-mini", default_max_model_turns: 8, default_turn_timeout_ms: 30_000, default_generation: %{ params: %{ temperature: 0.0, max_tokens: 500 } } import_config "#{config_env()}.exs" ``` -------------------------------- ### Execute Deterministic Browser Turn for Testing Source: https://github.com/agentjido/jidoka/blob/main/guides/browser-tools.md Uses a mock browser action module to simulate deterministic behavior during agent testing. ```elixir defmodule FakeSearchWeb do def run(_params, _context), do: {:ok, %{results: [%{title: "Hex docs", url: "https://hexdocs.pm/req"}]}} end Application.put_env(:jidoka, :browser_actions, %{search_web: FakeSearchWeb}) llm = fn _intent, journal, _ctx -> llm_calls = Enum.count(journal.results, fn {_id, r} -> r.kind == :llm end) case llm_calls do 0 -> {:ok, %{type: :operation, name: "search_web", arguments: %{"query" => "req"}}} 1 -> {:ok, %{type: :final, content: "Try hexdocs.pm/req."}} end end {:ok, result} = Jidoka.turn(MyApp.DocsAgent, "Where are Req docs?", llm: llm) ``` -------------------------------- ### Import agent configuration Source: https://github.com/agentjido/jidoka/blob/main/guides/public-facade.md Use Jidoka.import/2 to load agent specifications from JSON or YAML strings. ```elixir {:ok, spec} = Jidoka.import(""" agent: id: assistant model: openai:gpt-4o-mini instructions: Answer clearly and briefly. """) ``` -------------------------------- ### Run a deterministic turn loop Source: https://github.com/agentjido/jidoka/blob/main/guides/turn-runner-and-effect-interpreter.md Demonstrates a minimal TurnRunner execution using injected pure functions for LLM and operation capabilities. ```elixir alias Jidoka.Runtime.{Capabilities, TurnRunner} alias Jidoka.Turn spec = Jidoka.agent!( id: "runner_demo", model: %{provider: :test, id: "m"}, operations: [%{name: "echo", description: "echo args"}] ) {:ok, plan} = Jidoka.plan(spec) {:ok, request} = Turn.Request.from_input("hello") llm = fn _intent, journal, _ctx -> case Enum.count(journal.results, fn {_id, result} -> result.kind == :llm end) do 0 -> {:ok, %{type: :operation, name: "echo", arguments: %{"msg" => "hi"}}} 1 -> {:ok, %{type: :final, content: "done"}} end end ops = fn %Jidoka.Effect.Intent{payload: %{"arguments" => args}}, _journal, _ctx -> {:ok, %{echoed: args}} end {:ok, capabilities} = Capabilities.new(llm: llm, operations: ops) {:ok, %Turn.Result{content: "done"}} = TurnRunner.run(plan, request, capabilities) ``` -------------------------------- ### Mock AshJido tools for unit testing Source: https://github.com/agentjido/jidoka/blob/main/guides/ash-jido.md Replaces the default tool registration with a custom module to control available actions during tests. ```elixir defmodule MyApp.FakeAshTools do def actions(MyApp.Support.Ticket), do: [MyApp.Support.Generated.Read] end Application.put_env(:jidoka, :ash_jido_tools, MyApp.FakeAshTools) ``` -------------------------------- ### Initialize a Turn Request with Context Source: https://github.com/agentjido/jidoka/blob/main/guides/agent-orchestration.md Use this pattern to provide a task-local context map when testing a DSL agent directly, ensuring operation sources receive the specified data. ```elixir request = Jidoka.Turn.Request.new!( input: "Route this billing issue.", context: %{session_id: "case-123", tenant: "acme"} ) Jidoka.turn(MyApp.SupportRouter, request, llm: fake_llm ) ``` -------------------------------- ### Run Jidoka Tests Source: https://github.com/agentjido/jidoka/blob/main/guides/runic-spine-internals.md Commands to fetch dependencies and execute the workflow test suite. ```bash mix deps.get mix test test/jidoka/workflow_test.exs ``` -------------------------------- ### Defining Actions and Agents Source: https://github.com/agentjido/jidoka/blob/main/guides/core-concepts.md Implement tools as actions using the Jidoka.Action behavior and register them within an agent definition. ```elixir defmodule MyApp.LocalTime do use Jidoka.Action, name: "local_time", description: "Returns the local time for a city.", schema: Zoi.object(%{city: Zoi.string()}) @impl true def run(params, _context) do city = Map.get(params, :city) || Map.get(params, "city") {:ok, %{city: city, time: "09:30"}} end end defmodule MyApp.TimeAgent do use Jidoka.Agent agent :time_agent do model "openai:gpt-4o-mini" instructions "Use local_time for time questions." end tools do action MyApp.LocalTime end end ``` -------------------------------- ### Test memory persistence with InMemory store Source: https://github.com/agentjido/jidoka/blob/main/guides/memory.md Demonstrates how to verify that an agent correctly writes and recalls information using the Jidoka InMemory store within an ExUnit test. ```elixir defmodule MyApp.MemoryAgentTest do use ExUnit.Case, async: true setup do {:ok, pid} = Jidoka.Memory.Store.InMemory.start_link([]) {:ok, store: {Jidoka.Memory.Store.InMemory, pid: pid}} end test "recalls a remembered preference", %{store: store} do {:ok, _write} = Jidoka.Memory.write( MyApp.MemoryAgent.spec(), "User prefers the name Alex.", memory_store: store, session_id: "conv-1" ) {:ok, preflight} = Jidoka.preflight(MyApp.MemoryAgent, "hello", memory_store: store, session_id: "conv-1" ) system_message = Enum.find(preflight.prompt.messages, &(&1.role == :system)) assert system_message.content =~ "prefers the name Alex" llm = fn _intent, _journal, _ctx -> {:ok, %{type: :final, content: "Welcome back, Alex."}} end assert {:ok, result} = Jidoka.turn(MyApp.MemoryAgent, "hello", llm: llm, memory_store: store, session_id: "conv-1" ) assert result.content =~ "Alex" end end ``` -------------------------------- ### Add Skill Context Source: https://github.com/agentjido/jidoka/blob/main/guides/agent-dsl.md Integrates Jido.AI skill instructions and external skill files. ```elixir tools do skill MyApp.Skills.RefundPolicy load_path "priv/skills" end ``` -------------------------------- ### Configure Controls via YAML Source: https://github.com/agentjido/jidoka/blob/main/guides/controls.md Define control settings and operation triggers using a YAML structure. ```yaml controls: max_turns: 8 timeout: 30000 inputs: - control: no_secrets operations: - control: require_refund_approval when: kind: action name: refund_order outputs: - control: safe_reply ``` -------------------------------- ### Preflight Agent Prompts Source: https://github.com/agentjido/jidoka/blob/main/guides/kino-notebooks.md Renders a table of prompt messages and preflight events to verify wiring before execution. ```elixir {:ok, preflight} = Jidoka.Kino.preflight(MyApp.TimeAgent, "What time is it in Chicago?") length(preflight.prompt.messages) #=> 2 ``` -------------------------------- ### Standard Jidoka Project Directory Layout Source: https://github.com/agentjido/jidoka/blob/main/examples/README.md The recommended file structure for organizing agent definitions, scenarios, and tests within a Jidoka project. ```text examples// ├── README.md ├── manifest.yaml ├── example.exs ├── .livemd ├── lib/ │ ├── agent.ex │ ├── scenario.ex │ ├── scripted_llm.ex # optional for multi-step model behavior │ ├── actions/ │ ├── controls/ │ └── scenarios/ # optional for examples with several workflows └── test/ └── _test.exs ``` -------------------------------- ### Run Jidoka Tests Source: https://github.com/agentjido/jidoka/blob/main/examples/README.md Execute test suites using ExUnit tags or specific file paths. ```bash mix test --only example:support_agent mix test --only tool_calling mix test examples/durable_refund/test/execution_and_continuation_test.exs --trace ``` -------------------------------- ### Execute a chat turn in a notebook Source: https://github.com/agentjido/jidoka/blob/main/guides/kino-notebooks.md Run a chat interaction with a custom LLM function within the Kino environment. ```elixir Jidoka.Kino.chat("notebook demo", fn -> llm = fn _intent, _journal, _ctx -> {:ok, %{type: :final, content: "Hello from a deterministic notebook."}} end Jidoka.turn(Notebook.TimeAgent, "Say hello.", llm: llm) end) ``` -------------------------------- ### Configure and Add a Scheduled Workflow Source: https://github.com/agentjido/jidoka/blob/main/guides/workflows.md Initializes the background runner and scheduler, then adds a cron-based workflow schedule with specific execution policies. ```elixir children = [ {Jidoka.Workflow.Background, name: MyApp.WorkflowRunner}, {Jidoka.Workflow.Scheduler, name: MyApp.WorkflowScheduler, runner: MyApp.WorkflowRunner} ] {:ok, schedule} = Jidoka.Workflow.Scheduler.add(MyApp.WorkflowScheduler, %{ id: "weekday_refund_review", workflow: MyApp.Workflows.RefundReview, input: %{order_id: "A1001", amount: 42.50}, trigger: {:cron, "0 9 * * 1-5"}, timezone: "America/Chicago", overlap: :skip, misfire: :run_once, misfire_grace_ms: 1_000, cancellation: :future_only, retry: [max_attempts: 3] }) ``` -------------------------------- ### Import Agent Configuration Source: https://github.com/agentjido/jidoka/blob/main/README.md Loads agent specifications from YAML or JSON formats for execution. ```yaml version: 1 agent: id: assistant model: openai:gpt-4o-mini instructions: Answer clearly and briefly. ``` ```elixir {:ok, spec} = Jidoka.import(yaml) {:ok, text} = Jidoka.chat(spec, "Hello") ``` -------------------------------- ### Create an agent from runtime data Source: https://github.com/agentjido/jidoka/blob/main/guides/public-facade.md Use Jidoka.agent/1 to generate an agent specification dynamically at runtime. ```elixir {:ok, spec} = Jidoka.agent( id: "assistant", model: "openai:gpt-4o-mini", instructions: "Answer clearly and briefly." ) ``` -------------------------------- ### Run quality gate Source: https://github.com/agentjido/jidoka/blob/main/CONTRIBUTING.md Execute these commands to validate the package before submitting a pull request. ```bash mix quality mix test --cover mix hex.build --unpack ``` -------------------------------- ### Execute Live Turn Source: https://github.com/agentjido/jidoka/blob/main/guides/troubleshooting.md Run a single iteration to isolate provider errors while avoiding long execution loops. ```elixir Jidoka.turn(MyApp.TimeAgent, failing_input, max_turns: 1) ```