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

# Camel.agents.programmed agent instruction

<a id="camel.agents.programmed_agent_instruction" />

<a id="camel.agents.programmed_agent_instruction.ProgrammableAgentRequirement" />

## ProgrammableAgentRequirement

```python theme={"system"}
class ProgrammableAgentRequirement(Enum):
```

Requirements for programmable agent state.

Defines the possible requirements that can be used to repair the state
of a programmable agent.

**Parameters:**

* **LAST\_MESSAGE\_NOT\_USER** (str): Requires that the last message in the conversation was not from the user.

<a id="camel.agents.programmed_agent_instruction.ProgrammedAgentInstructionResult" />

## ProgrammedAgentInstructionResult

```python theme={"system"}
class ProgrammedAgentInstructionResult(BaseModel):
```

Result of a programmable agent instruction execution.

Contains the messages exchanged during execution and the computed value.
The value type is specified by the generic type parameter T.

**Parameters:**

* **user\_message** (BaseMessage): The message sent by the user.
* **agent\_message** (BaseMessage): The message sent by the agent.
* **value** (T): The computed result value of type T.

<a id="camel.agents.programmed_agent_instruction.AbstractProgrammableAgent" />

## AbstractProgrammableAgent

```python theme={"system"}
class AbstractProgrammableAgent(ABC):
```

Abstract class for a programmable agent.

A programmable agent is an agent that can be programmed to perform a
specific function or task. This class defines the interface for a
programmable agent.

These methods should be implemented in order to ensure the agent supports
the necessary guarantees to enable a programming interface while
maintaining compatibility in a multi-agent system.

A programmable agent is responsible for providing and maintaining a
programming interface for its functionality.

<a id="camel.agents.programmed_agent_instruction.AbstractProgrammableAgent.run_atomic" />

### run\_atomic

```python theme={"system"}
def run_atomic(
    self,
    callback: Callable[[], ProgrammedAgentInstructionResult[T]]
):
```

Run an atomic operation on the agent.

An atomic operation is an operation that is guaranteed to
be executed without interruption by any other operation.

**Parameters:**

* **callback** (Callable\[\[], ProgrammedAgentInstructionResult\[T]]): The operation to execute atomically.

**Returns:**

ProgrammedAgentInstructionResult\[T]: The result of the operation.

<a id="camel.agents.programmed_agent_instruction.AbstractProgrammableAgent.repair_state" />

### repair\_state

```python theme={"system"}
def repair_state(self, requirement: ProgrammableAgentRequirement):
```

Repair the state of the agent.

Agents may have other non-atomic interfaces, such as a user interface,
or chat between other agents. This method should restore the agent to
a state where it can perform operations according to the specified
requirement.

**Parameters:**

* **requirement** (ProgrammableAgentRequirement): The requirement to repair the state for.

<a id="camel.agents.programmed_agent_instruction.programmable_capability" />

## programmable\_capability

```python theme={"system"}
def programmable_capability(func: Callable[..., ProgrammedAgentInstructionResult[T]]):
```

Decorator for programmable agent capabilities.

This decorator ensures that the decorated method is executed atomically
and maintains the agent's state guarantees.

**Parameters:**

* **func** (Callable\[..., ProgrammedAgentInstructionResult\[T]]): The method to decorate.

**Returns:**

Callable\[..., ProgrammedAgentInstructionResult\[T]]: The decorated
method that ensures atomic execution.

<a id="camel.agents.programmed_agent_instruction.ProgrammableChatAgent" />

## ProgrammableChatAgent

```python theme={"system"}
class ProgrammableChatAgent(ChatAgent, AbstractProgrammableAgent):
```

A chat agent that can be programmed to perform specific tasks.

Provides a default implementation of atomic execution using threading locks
and basic state tracking for message roles. Implementing classes need to
provide specific repair logic for their use cases.

**Parameters:**

* **\_operation\_lock** (threading.Lock): Lock for ensuring atomic operations.
* **\_last\_message\_role** (Optional\[str]): Role of the last message in the conversation.

<a id="camel.agents.programmed_agent_instruction.ProgrammableChatAgent.__init__" />

### **init**

```python theme={"system"}
def __init__(self, **kwargs: Any):
```

Initialize the ProgrammableChatAgent.

<a id="camel.agents.programmed_agent_instruction.ProgrammableChatAgent.run_atomic" />

### run\_atomic

```python theme={"system"}
def run_atomic(
    self,
    callback: Callable[[], ProgrammedAgentInstructionResult[T]]
):
```

Run an atomic operation on the agent.

Ensures thread-safe execution of the callback function by using a lock.

**Parameters:**

* **callback** (Callable\[\[], ProgrammedAgentInstructionResult\[T]]): The operation to execute atomically.

**Returns:**

ProgrammedAgentInstructionResult\[T]: The result of the operation.

<a id="camel.agents.programmed_agent_instruction.ProgrammableChatAgent.repair_state" />

### repair\_state

```python theme={"system"}
def repair_state(self, requirement: ProgrammableAgentRequirement):
```

Repair the state of the agent.

Implements basic state repair for message role requirements.

**Parameters:**

* **requirement** (ProgrammableAgentRequirement): The requirement to repair the state for.
