Skip to content

2. Create an Agent with the CLI

In this section, we will create an agent using ant, the Claude Platform CLI.

  1. Install ant.

    1. From the ant releases page, download ant_{version}_windows_amd64.zip.

    2. Extract it to any location.

    3. Launch powershell.exe in the extracted folder.

    4. Set the character encoding to UTF-8 so that non-ASCII text in command output does not get garbled.

      Terminal window
      $OutputEncoding = [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding $false
  2. Run ant auth login.

    1. Run the following command.
      Terminal window
      ./ant auth login
  3. Log in via your browser.

From here on, we will recreate the same setup you built through the UI in 1. Create an Agent in the Console (credential vault → environment → agent → session), this time entirely with ant commands. To avoid name collisions with the console version, the CLI versions have “-cli” appended to their names.

  1. Create a vault and save its ID in a variable.

    Terminal window
    $VAULT_ID = ./ant beta:vaults create --display-name "Vault-cli" --transform id --raw-output

    Display the contents of the variable and confirm that an ID starting with vlt_ has been saved.

    Terminal window
    $VAULT_ID
  2. Add your Jina AI API key to the vault as a credential. Replace YOUR_API_KEY_HERE with your actual API key before running (the command is a single line).

    Terminal window
    ./ant beta:vaults:credentials create --vault-id $VAULT_ID --display-name "Jina-ai-cli" --auth '{type: static_bearer, mcp_server_url: https://mcp.jina.ai/v1, token: YOUR_API_KEY_HERE}'
  1. Create an environment that allows network access to MCP servers, and save its ID in a variable (the command is a single line).

    Terminal window
    $ENVIRONMENT_ID = ./ant beta:environments create --name "Jina-environment-cli" --config '{type: cloud, networking: {type: limited, allow_mcp_servers: true}}' --transform id --raw-output

    Display the contents of the variable and confirm that an ID starting with env_ has been saved.

    Terminal window
    $ENVIRONMENT_ID
  1. In the folder where you are running the commands, create a file named agent.yaml with the following content.

    agent.yaml
    name: Jina Web Research Agent CLI
    model:
    id: claude-haiku-4-5
    speed: standard
    description: A demo agent for web search, page reading, and academic research using the Jina AI MCP server.
    system: You are a research assistant that leverages Jina AI's search and reading tools. When you receive a question, use search_web (or search_arxiv / search_ssrn for academic topics) to find relevant sources, then use read_url or parallel_read_url to fetch the full text of promising results. Do not rely on search result snippets alone. Combine information from multiple sources, cite the URLs you used, and clearly indicate any uncertainty or conflicting information. For efficiency, prefer the parallel_* tools when searching or reading multiple sources at once. If asked to summarize or extract facts from a specific page, read that page directly with read_url. Keep your answers concise and well organized, and base them on the retrieved content rather than prior knowledge.
    mcp_servers:
    - name: jina
    type: url
    url: https://mcp.jina.ai/v1
    tools:
    - type: mcp_toolset
    mcp_server_name: jina
    default_config:
    enabled: true
    permission_policy:
    type: always_allow
    skills: []
    metadata: {}
  2. Create the agent by feeding it agent.yaml, and save its ID in a variable.

    Terminal window
    $AGENT_ID = Get-Content agent.yaml -Raw -Encoding UTF8 | ./ant beta:agents create --transform id --raw-output

    Display the contents of the variable and confirm that an ID starting with agent_ has been saved.

    Terminal window
    $AGENT_ID
  1. Confirm that all three IDs saved so far are in place.

    Terminal window
    $AGENT_ID; $ENVIRONMENT_ID; $VAULT_ID
  2. Create a session by specifying the agent, environment, and vault IDs, and save its ID in a variable (the command is a single line).

    Terminal window
    $SESSION_ID = ./ant beta:sessions create --agent $AGENT_ID --environment-id $ENVIRONMENT_ID --vault-id $VAULT_ID --transform id --raw-output

    Display the contents of the variable and confirm that an ID starting with sesn_ has been saved.

    Terminal window
    $SESSION_ID
  1. You will use two terminals: one receives events in real time while the other sends the message. First, start streaming events in the window you have been using so far (terminal 1).

    Terminal window
    ./ant beta:sessions:events stream --session-id $SESSION_ID --format jsonl

    Leave the command running and let it wait for events to arrive. Because --format jsonl is set, events are printed one per line in JSON format.

  2. Open a new window (terminal 2) and get ready to send. Variables are independent per window, so set $SESSION_ID in terminal 2 as well. Replace your session ID here with the ID starting with sesn_ that was displayed in 5. Create a session (you can find it by scrolling back through terminal 1).

    Start a new PowerShell in the folder where you extracted ant and run the following.

    Terminal window
    $OutputEncoding = [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding $false
    $SESSION_ID = "your session ID here"
  3. Send the message from terminal 2 (the command is a single line).

    Terminal window
    ./ant beta:sessions:events send --session-id $SESSION_ID --event '{type: user.message, content: [{type: text, text: "Search for the latest papers on RAG"}]}'

    Once you send it, events starting with user.message begin to flow in terminal 1. Following the MCP tool calls (agent.mcp_tool_use), the answer arrives as the text of an agent.message event. When session.status_idle appears, the run is complete.

    After you have checked the answer, press Ctrl+C in terminal 1 to stop the stream.

    If you missed the output, you can check it in the event history. Events are printed one per line, and the text on the agent.message line is the answer.

    Terminal window
    ./ant --format jsonl --transform '{type,text:content.0.text}' beta:sessions:events list --session-id $SESSION_ID
  4. If you open the same session from the “Sessions” menu in the console, you can also review the conversation on screen.

  • We reproduced the same setup we built in the console (vault → environment → agent → session) using nothing but ant commands.
  • Beta APIs are called with beta:-prefixed commands. We used --transform id --raw-output to extract just the ID from each response and passed it to the next command via variables.
  • Configuration can be passed either as one-line flags (--auth, --event) or as a YAML file (agent.yaml).
  • To interact with a session, send messages with events send and check results with events stream (or by listing the event history).

Great work! Please share your thoughts so far in a post on X.

Share your thoughts on X