Skip to main content

Quickstart

Get a Cortex agent running locally in four steps.

1. Install Cortex

pip install cortex-runtime==2.5.10

2. Initialize and Build

Unlike legacy versions, Cortex v2.5.10 uses a build-first workflow to ensure environment consistency and optimize the Shared KV Cache.

# Detect architecture and prime the local cache
cortex build

3. Define your agent

Create a cortex.yaml in your project directory:

version: "2"
project: my-first-agent

agents:
- name: assistant
runtime: python3.12
entrypoint: agent:run
resources:
cpu_limit: 1.0
mem_limit: 1Gi
capabilities:
- network.access: ["api.openai.com"]
- turbo_mode: true # Enable 3x parallel speedup

4. Write the agent logic

Create agent.py in the same directory:

import os
from openai import OpenAI

def run():
client = OpenAI(base_url=os.environ.get("ICE_URL", "https://api.openai.com/v1"))

while True:
user_input = input("You: ")
if user_input.lower() in ("exit", "quit"):
break

response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": user_input}],
extra_headers={
"X-Session-Id": os.environ.get("CORTEX_SESSION_ID", "default"),
"X-User-Id": os.environ.get("CORTEX_USER_ID", "user")
}
)
print(f"Agent: {response.choices[0].message.content}")

5. Run it

# Bundle the project
cortex bundle --config cortex.yaml --output my-first-agent.cortex

# Run it
cortex run my-first-agent.cortex

Or run directly without bundling during development:

cortex dev --config cortex.yaml

Next Steps