> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hypertic.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

Get started with Hypertic by building an AI agent that demonstrates core features: tools for extending capabilities, memory for maintaining conversation context, and model configuration for consistent behavior.

This guide walks you through creating an agent that uses weather and date tools, maintains conversation history with in-memory storage (use PostgreSQL/MongoDB in production), and can handle both synchronous and asynchronous operations with streaming support.

<Steps>
  <Step title="Set up environment">
    Create a virtual environment to isolate your project dependencies.

    <CodeGroup>
      ```bash Mac theme={null} theme={null}
      python -m venv venv
      source venv/bin/activate
      ```

      ```bash Windows theme={null} theme={null}
      python -m venv venv
      venv\Scripts\activate
      ```
    </CodeGroup>
  </Step>

  <Step title="Install dependencies">
    Install Hypertic and the OpenAI package using pip or uv.

    <CodeGroup>
      ```bash pip theme={null} theme={null}
      pip install hypertic openai
      ```

      ```bash uv theme={null} theme={null}
      uv add hypertic openai
      ```
    </CodeGroup>
  </Step>

  <Step title="Set API key">
    Export your OpenAI API key as an environment variable.

    <CodeGroup>
      ```bash Mac theme={null} theme={null}
      export OPENAI_API_KEY=sk-***
      ```

      ```bash Windows theme={null} theme={null}
      setx OPENAI_API_KEY sk-***
      ```
    </CodeGroup>
  </Step>

  <Step title="Create tools">
    Define tool functions that your agent can use to interact with external systems.

    ```python theme={null} theme={null}
    from hypertic.tools import tool
    from datetime import datetime

    # Define a weather tool
    @tool
    def get_weather(city: str) -> str:
        """Get weather for a given city."""
        # In production, this would call a real weather API
        return f"Sunny, 72°F in {city}"

    # Define a date tool
    @tool
    def get_current_date() -> str:
        """Get the current date and time."""
        return datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    ```
  </Step>

  <Step title="Configure model">
    Initialize your language model with the desired parameters.

    ```python theme={null} theme={null}
    from hypertic.models import OpenAI

    # Configure the model
    model = OpenAI(
      model="gpt-5.2",
      max_tokens=1000,
      temperature=0.5,
    )
    ```
  </Step>

  <Step title="Add memory">
    Set up memory to store conversation history and maintain context across sessions. For this demo, we'll use in-memory storage (use PostgreSQL/MongoDB in production).

    ```python theme={null} theme={null}
    from hypertic.memory import InMemory

    # Create in-memory memory (for demo - use PostgreSQL/MongoDB in production)
    memory = InMemory()
    ```
  </Step>

  <Step title="Configure agent">
    Create your agent with the model, tools, and memory configuration.

    ```python theme={null} theme={null}
    from hypertic.agents import Agent

    # Create an agent with memory
    agent = Agent(
        model=model,
        instructions="", # If you want you can add instructions also.
        tools=[get_weather, get_current_date],
        memory=memory
    )
    ```
  </Step>

  <Step title="Run the agent">
    Execute your agent with a query and get a response. You can use synchronous, asynchronous, or streaming methods.

    <CodeGroup>
      ```python Sync theme={null} theme={null}
      # Synchronous non-streaming
      response = agent.run("What is today's date and how's the weather in San Francisco?")
      print(response.content)
      ```

      ```python Async theme={null} theme={null}
      import asyncio
      # Asynchronous non-streaming
      async def main():
          response = await agent.arun("What is today's date and how's the weather in San Francisco?")
          print(response.content)
      asyncio.run(main())
      ```
    </CodeGroup>

    ```text theme={null} theme={null}
    Today's date is 2024-01-15. The weather in San Francisco is sunny, 72°F.
    ```
  </Step>
</Steps>

<Expandable title="Full example code">
  <CodeGroup>
    ```python Sync theme={null} theme={null}
    from hypertic import Agent, tool
    from hypertic.memory import InMemory
    from openai import OpenAI
    from datetime import datetime

    # Define a weather tool
    @tool
    def get_weather(city: str) -> str:
        """Get weather for a given city."""
        return f"Sunny, 72°F in {city}"

    # Define a date tool
    @tool
    def get_current_date() -> str:
        """Get the current date and time."""
        return datetime.now().strftime("%Y-%m-%d %H:%M:%S")

    # Configure the model
    model = OpenAI(
        model="gpt-5.2",
        max_tokens=1000,
        temperature=0.5,
    )

    # Create in-memory memory (use PostgreSQL/MongoDB in production)
    memory = InMemory()

    # Create an agent with memory
    agent = Agent(
        model=model,
        instructions="",
        tools=[get_weather, get_current_date],
        memory=memory
    )

    # Synchronous non-streaming
    response = agent.run("What is today's date and how's the weather in San Francisco?")
    print(response.content)
    ```

    ```python Async theme={null} theme={null}
    import asyncio
    from hypertic import Agent, tool
    from hypertic.memory import InMemory
    from openai import OpenAI
    from datetime import datetime

    # Define a weather tool
    @tool
    def get_weather(city: str) -> str:
        """Get weather for a given city."""
        return f"Sunny, 72°F in {city}"

    # Define a date tool
    @tool
    def get_current_date() -> str:
        """Get the current date and time."""
        return datetime.now().strftime("%Y-%m-%d %H:%M:%S")

    # Configure the model
    model = OpenAI(
        model="gpt-5.2",
        max_tokens=1000,
        temperature=0.5,
    )

    # Create in-memory memory (use PostgreSQL/MongoDB in production)
    memory = InMemory()

    # Create an agent with memory
    agent = Agent(
        model=model,
        instructions="",
        tools=[get_weather, get_current_date],
        memory=memory
    )

    # Asynchronous non-streaming
    async def main():
        response = await agent.arun("What is today's date and how's the weather in San Francisco?")
        print(response.content)

    asyncio.run(main())
    ```

    ```python Streaming theme={null} theme={null}
    import asyncio
    from hypertic import Agent, tool
    from hypertic.memory import InMemory
    from openai import OpenAI
    from datetime import datetime

    # Define a weather tool
    @tool
    def get_weather(city: str) -> str:
        """Get weather for a given city."""
        return f"Sunny, 72°F in {city}"

    # Define a date tool
    @tool
    def get_current_date() -> str:
        """Get the current date and time."""
        return datetime.now().strftime("%Y-%m-%d %H:%M:%S")

    # Configure the model
    model = OpenAI(
        model="gpt-5.2",
        max_tokens=1000,
        temperature=0.5,
    )

    # Create in-memory memory (use PostgreSQL/MongoDB in production)
    memory = InMemory()

    # Create an agent with memory
    agent = Agent(
        model=model,
        instructions="",
        tools=[get_weather, get_current_date],
        memory=memory
    )

    # Streaming response
    async def main():
        async for event in agent.astream("What is today's date and how's the weather in San Francisco?"):
            if event.type == "content":
                print(event.content, end="", flush=True)

    asyncio.run(main())
    ```
  </CodeGroup>
</Expandable>

Congratulations! You've built your first AI agent with Hypertic that can use tools and remember context.
