# SDK Reference

Welcome to the Skillful AI Web SDK reference documentation. Here you'll find detailed information about the classes, methods, and properties available in the SDK.

## 🔷 SkillfulClient

The `SkillfulClient` is the main entry point for interacting with Skillful AI agents.

### Initialization

```javascript
import { SkillfulClient } from '@skillfulai/agents';

const client = new SkillfulClient({
    apiKey: 'your-api-key'
});
```

### Core Methods

#### 🟣 Agent Management

<details>

<summary><code>getAgents()</code></summary>

Retrieves all available agents.

```javascript
const agents = await client.getAgents();
```

**Returns**: `Array<Agent>` - List of available agents

</details>

<details>

<summary><code>setAgent(agentOrName)</code></summary>

Sets the active agent for conversations.

```javascript
// By name
await client.setAgent('Wojak');

// By agent object
await client.setAgent(agents[0]);
```

**Parameters**:

* `agentOrName`: `string | Agent` - Agent name or object

**Returns**: `Promise<Agent>` - The set agent

</details>

#### 🟣 Conversation Methods

<details>

<summary><code>sendMessage(content)</code></summary>

Sends a message to the active agent.

```javascript
const response = await client.sendMessage('Hello!');
```

**Parameters**:

* `content`: `string` - Message to send

**Returns**:

```typescript
{
    text: string;      // Agent's response
    events: any[];     // Event metadata
    tools: any[];      // Tools used
    sources: any[];    // Source references
}
```

</details>

<details>

<summary><code>getConversationHistory()</code></summary>

Gets the current conversation history.

```javascript
const history = client.getConversationHistory();
```

**Returns**: Array of message objects

```typescript
Array<{
    role: 'user' | 'assistant';
    content: string;
}>
```

</details>

<details>

<summary><code>clearConversation()</code></summary>

Clears the current conversation history.

```javascript
client.clearConversation();
```

</details>

## 🔷 Agent

The `Agent` class represents an AI agent and provides access to its properties and capabilities.

### Properties

```typescript
agent.id: string          // Unique identifier
agent.name: string        // Agent name
agent.description: string // Description
agent.logoUrl: string    // Logo URL
agent.type: string       // Agent type
agent.isDraft: boolean   // Draft status
agent.isMinted: boolean  // Minting status
```

### Methods

<details>

<summary><code>findAgentByName(name)</code></summary>

Finds a specific agent by name.

```javascript
const wojak = await client.findAgentByName('Wojak');
```

**Parameters**:

* `name`: `string` - Name of the agent to find

**Returns**: `Promise<Agent | null>` - Found agent or null

</details>

<details>

<summary><code>hasSkill(skillName)</code></summary>

Checks if the agent has a specific skill.

```javascript
const hasWeather = agent.hasSkill('weather');
```

**Parameters**:

* `skillName`: `string` - Name of the skill to check

**Returns**: `boolean`

</details>

<details>

<summary><code>getLLMInfo()</code></summary>

Gets the agent's language model configuration.

```javascript
const llmInfo = agent.getLLMInfo();
```

**Returns**:

```typescript
{
    provider: string;    // LLM provider
    model: string;      // Model name
    temperature: number; // Temperature setting
    maxTokens: number;  // Max tokens
}
```

</details>

## 🔷 Response Structure

When receiving a response from `sendMessage()`, you get:

```typescript
{
    text: string;    // The agent's response text
    events: Array<{
        type: string;
        data: any;
    }>;
    tools: Array<{
        type: string;
        data: any;
    }>;
    sources: {
        type: string;
        data: {
            nodes: any[];
        };
    };
}
```

## 🔷 Error Handling

The SDK provides detailed error messages for common issues:

```javascript
try {
    await client.sendMessage('Hello');
} catch (error) {
    // Handle specific error types
    if (error.message.includes('No active agent')) {
        console.error('Please select an agent first');
    } else if (error.message.includes('unauthorized')) {
        console.error('Invalid API key');
    } else {
        console.error('Unexpected error:', error.message);
    }
}
```
