Skip to content

Warrior

An AI agent that fights in The Arena.


Warrior

orc.themed.warrior.Warrior

A Warrior is an agent that fights in The Arena.

The wrapper is ORC-themed, but the arguments are standard AI concepts.

Example

grog = Warrior( name="Grog", llm_client="gpt-4o", # Standard AI model system_prompt="You are a senior python backend dev...", temperature=0.2, capabilities=["code_review", "debugging"], domains=["backend", "python"], )

Source code in orc/themed/warrior.py
class Warrior:
    """A Warrior is an agent that fights in The Arena.

    The wrapper is ORC-themed, but the arguments are standard AI concepts.

    Example:
        grog = Warrior(
            name="Grog",
            llm_client="gpt-4o",           # Standard AI model
            system_prompt="You are a senior python backend dev...",
            temperature=0.2,
            capabilities=["code_review", "debugging"],
            domains=["backend", "python"],
        )
    """

    def __init__(
        self,
        name: str,
        llm_client: Union[str, Any],
        system_prompt: str,
        temperature: float = 0.7,
        capabilities: Optional[List[str]] = None,
        domains: Optional[List[str]] = None,
    ):
        """
        Initialize a Warrior.

        Args:
            name: Warrior's name (unique identifier).
            llm_client: Either a string (model name) or LLMProvider instance.
            system_prompt: System prompt defining the warrior's expertise.
            temperature: LLM temperature (0-1). Default 0.7.
            capabilities: List of capabilities this warrior possesses.
            domains: List of domains this warrior claims expertise in.
        """
        self._name = name
        self.llm_client = llm_client
        self.system_prompt = system_prompt
        self.temperature = temperature
        self._capabilities = capabilities or []
        self._domains = domains or []

    @property
    def name(self) -> str:
        """Unique warrior identifier."""
        return self._name

    @property
    def capabilities(self) -> List[str]:
        """List of capabilities this warrior supports."""
        return self._capabilities

    @property
    def domains(self) -> List[str]:
        """List of domains this warrior claims expertise in."""
        return self._domains

    async def process_task(
        self,
        task_description: str,
        context: Optional[Dict[str, Any]] = None,
    ) -> TaskResult:
        """
        Execute a task.

        If llm_client is a string (model name), returns a mock success result.
        If llm_client is an LLMProvider instance, calls it to process the task.

        Args:
            task_description: Natural language description of the task.
            context: Execution context.

        Returns:
            TaskResult with the outcome.
        """
        context = context or {}
        task_id = context.get("task_id", "unknown")

        try:
            if isinstance(self.llm_client, str):
                # Mock mode: simulate variable performance
                duration = random.randint(50, 500)
                return TaskResult.success(
                    task_id=task_id,
                    data={
                        "response": f"Warrior {self.name} processed task: {task_description}",
                        "model": self.llm_client,
                    },
                    duration_ms=duration,
                )

            # Real LLM mode: call the provider
            if hasattr(self.llm_client, "complete"):
                import time

                from dynabots_core import LLMMessage

                start = time.perf_counter()
                response = await self.llm_client.complete(
                    messages=[
                        LLMMessage(role="system", content=self.system_prompt),
                        LLMMessage(role="user", content=task_description),
                    ],
                    temperature=self.temperature,
                )
                elapsed_ms = int((time.perf_counter() - start) * 1000)

                return TaskResult.success(
                    task_id=task_id,
                    data={
                        "response": response.content,
                        "model": getattr(self.llm_client, "model", "unknown"),
                    },
                    duration_ms=elapsed_ms,
                )
            else:
                return TaskResult.success(
                    task_id=task_id,
                    data={
                        "response": (
                            f"Warrior {self.name} processed task "
                            f"(no LLM): {task_description}"
                        )
                    },
                )

        except Exception as e:
            return TaskResult.failure(
                task_id=task_id,
                error=f"Warrior {self.name} failed to process task: {str(e)}",
            )

    async def health_check(self) -> bool:
        """Check if this warrior is healthy and ready to fight."""
        # Basic implementation: always healthy if instantiated
        return True

capabilities property

List of capabilities this warrior supports.

domains property

List of domains this warrior claims expertise in.

name property

Unique warrior identifier.

__init__(name, llm_client, system_prompt, temperature=0.7, capabilities=None, domains=None)

Initialize a Warrior.

Parameters:

Name Type Description Default
name str

Warrior's name (unique identifier).

required
llm_client Union[str, Any]

Either a string (model name) or LLMProvider instance.

required
system_prompt str

System prompt defining the warrior's expertise.

required
temperature float

LLM temperature (0-1). Default 0.7.

0.7
capabilities Optional[List[str]]

List of capabilities this warrior possesses.

None
domains Optional[List[str]]

List of domains this warrior claims expertise in.

None
Source code in orc/themed/warrior.py
def __init__(
    self,
    name: str,
    llm_client: Union[str, Any],
    system_prompt: str,
    temperature: float = 0.7,
    capabilities: Optional[List[str]] = None,
    domains: Optional[List[str]] = None,
):
    """
    Initialize a Warrior.

    Args:
        name: Warrior's name (unique identifier).
        llm_client: Either a string (model name) or LLMProvider instance.
        system_prompt: System prompt defining the warrior's expertise.
        temperature: LLM temperature (0-1). Default 0.7.
        capabilities: List of capabilities this warrior possesses.
        domains: List of domains this warrior claims expertise in.
    """
    self._name = name
    self.llm_client = llm_client
    self.system_prompt = system_prompt
    self.temperature = temperature
    self._capabilities = capabilities or []
    self._domains = domains or []

health_check() async

Check if this warrior is healthy and ready to fight.

Source code in orc/themed/warrior.py
async def health_check(self) -> bool:
    """Check if this warrior is healthy and ready to fight."""
    # Basic implementation: always healthy if instantiated
    return True

process_task(task_description, context=None) async

Execute a task.

If llm_client is a string (model name), returns a mock success result. If llm_client is an LLMProvider instance, calls it to process the task.

Parameters:

Name Type Description Default
task_description str

Natural language description of the task.

required
context Optional[Dict[str, Any]]

Execution context.

None

Returns:

Type Description
TaskResult

TaskResult with the outcome.

Source code in orc/themed/warrior.py
async def process_task(
    self,
    task_description: str,
    context: Optional[Dict[str, Any]] = None,
) -> TaskResult:
    """
    Execute a task.

    If llm_client is a string (model name), returns a mock success result.
    If llm_client is an LLMProvider instance, calls it to process the task.

    Args:
        task_description: Natural language description of the task.
        context: Execution context.

    Returns:
        TaskResult with the outcome.
    """
    context = context or {}
    task_id = context.get("task_id", "unknown")

    try:
        if isinstance(self.llm_client, str):
            # Mock mode: simulate variable performance
            duration = random.randint(50, 500)
            return TaskResult.success(
                task_id=task_id,
                data={
                    "response": f"Warrior {self.name} processed task: {task_description}",
                    "model": self.llm_client,
                },
                duration_ms=duration,
            )

        # Real LLM mode: call the provider
        if hasattr(self.llm_client, "complete"):
            import time

            from dynabots_core import LLMMessage

            start = time.perf_counter()
            response = await self.llm_client.complete(
                messages=[
                    LLMMessage(role="system", content=self.system_prompt),
                    LLMMessage(role="user", content=task_description),
                ],
                temperature=self.temperature,
            )
            elapsed_ms = int((time.perf_counter() - start) * 1000)

            return TaskResult.success(
                task_id=task_id,
                data={
                    "response": response.content,
                    "model": getattr(self.llm_client, "model", "unknown"),
                },
                duration_ms=elapsed_ms,
            )
        else:
            return TaskResult.success(
                task_id=task_id,
                data={
                    "response": (
                        f"Warrior {self.name} processed task "
                        f"(no LLM): {task_description}"
                    )
                },
            )

    except Exception as e:
        return TaskResult.failure(
            task_id=task_id,
            error=f"Warrior {self.name} failed to process task: {str(e)}",
        )