Skip to main content

Model Module Overview

The ARKOS Model Module provides an asynchronous interface for communicating with LLMs using the AsyncOpenAI client. It’s designed to work with SGLANG servers and any OpenAI-compatible endpoint.

Core Components

ArkModelLink

Main class for LLM communication using AsyncOpenAI

Message Classes

Pydantic models for different message types

Async Support

Non-blocking I/O for better performance

Streaming

Real-time token streaming for responsive UX

Architecture

Message Classes

All messages extend the base Message Pydantic model:

Initialization

Configuration Options

Core Methods

generate_response()

Main method for getting LLM responses:
Usage:

generate_stream()

Stream tokens as they’re generated:
Usage:

make_llm_call()

Low-level method for API calls:

Structured Output

Use JSON schemas for structured responses:

Message Formatting

Messages are automatically converted to OpenAI format:

Integration with Agent

The Agent module uses ArkModelLink through call_llm():

AsyncOpenAI Client

The module uses AsyncOpenAI internally:

Configuration via YAML

Configure the LLM endpoint in config_module/config.yaml:
Access in code:

Error Handling

Streaming Implementation

SGLANG Server

The model module is designed to work with SGLANG:
This runs Qwen 2.5-7B-Instruct with an OpenAI-compatible API.

Verify Server

Testing

Basic test example:

Best Practices

  1. Use async/await: All LLM calls should be awaited
  2. Set appropriate timeouts: Prevent hanging on slow responses
  3. Handle errors gracefully: Catch exceptions and provide fallbacks
  4. Use streaming for UX: Better user experience for long responses
  5. Validate schemas: Test JSON schemas before production use

Troubleshooting

Ensure SGLANG server is running:
Check GPU utilization and model loading:
Verify your schema matches expected output:

Next Steps

Agent Module

Learn about agent orchestration

Memory Module

Explore memory integration

Tool Module

Understand tool calling

Development Setup

Set up your environment