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

# ToolCall

# Class: ToolCall

Defined in: [src/lib/logger/components/toolCall.ts:61](https://github.com/maximhq/maxim-js/blob/main/src/lib/logger/components/toolCall.ts#L61)

Represents a function or tool call.

Tool calls capture the invocation of external APIs, internal functions,
or any callable operations made via tool calls in your AI application.
They track the complete lifecycle including arguments, results, timing, and
errors.

ToolCall

## Example

```ts theme={null}
const toolCallArgs = {
  userId: '12345',
  fields: ['name', 'email', 'preferences']
};

const toolCall = container.toolCall({
  id: 'database-query-001',
  name: 'query_user_database',
  description: 'Queries the user database for customer information',
  args: JSON.stringify(toolCallArgs),
});

// Execute and record result
try {
  const userData = await query(toolCallArgs);
  toolCall.result(JSON.stringify(userData));
} catch (error) {
  toolCall.error({
    message: error.message,
    code: 'DB_CONNECTION_ERROR',
    type: 'DatabaseError'
  });
}
```

## Extends

* [`BaseContainer`](./BaseContainer)

## Constructors

### Constructor

> **new ToolCall**(`config`, `writer`): `ToolCall`

Defined in: [src/lib/logger/components/toolCall.ts:78](https://github.com/maximhq/maxim-js/blob/main/src/lib/logger/components/toolCall.ts#L78)

Creates a new tool call log entry.

#### Parameters

##### config

[`ToolCallConfig`](../interfaces/ToolCallConfig)

Configuration object defining the tool call

##### writer

[`LogWriter`](./LogWriter)

Log writer instance for persisting tool call data

#### Returns

`ToolCall`

#### Example

```ts theme={null}
const toolCall = container.toolCall({
  id: 'api-call-001',
  name: 'get_user_profile',
  description: 'Fetches user profile data from the database',
  args: JSON.stringify({ userId: '12345', fields: ['name', 'email'] }),
});
```

#### Overrides

[`BaseContainer`](./BaseContainer).[`constructor`](./BaseContainer#constructor)

## Accessors

### id

#### Get Signature

> **get** **id**(): `string`

Defined in: [src/lib/logger/components/base.ts:80](https://github.com/maximhq/maxim-js/blob/main/src/lib/logger/components/base.ts#L80)

Gets the unique identifier for this container.

##### Returns

`string`

The container's unique ID

#### Inherited from

[`BaseContainer`](./BaseContainer).[`id`](./BaseContainer#id)

## Methods

### addMetadata()

> **addMetadata**(`metadata`): `void`

Defined in: [src/lib/logger/components/base.ts:124](https://github.com/maximhq/maxim-js/blob/main/src/lib/logger/components/base.ts#L124)

Adds metadata to this container for additional context and debugging. Any data type could be added as the value in the metadata record.

#### Parameters

##### metadata

`Record`\<`string`, `unknown`>

Key-value pairs of metadata

#### Returns

`void`

void

#### Example

```ts theme={null}
container.addMetadata({
  requestId: 'req-123',
  userAgent: 'Mozilla/5.0...',
  processingTime: 1500
});
```

#### Inherited from

[`BaseContainer`](./BaseContainer).[`addMetadata`](./BaseContainer#addmetadata)

***

### addTag()

> **addTag**(`key`, `value`): `void`

Defined in: [src/lib/logger/components/base.ts:94](https://github.com/maximhq/maxim-js/blob/main/src/lib/logger/components/base.ts#L94)

Adds a tag to this container for categorization and filtering.

#### Parameters

##### key

`string`

The tag key

##### value

`string`

The tag value

#### Returns

`void`

void

#### Example

```ts theme={null}
container.addTag('environment', 'production');
container.addTag('user_type', 'premium');
```

#### Inherited from

[`BaseContainer`](./BaseContainer).[`addTag`](./BaseContainer#addtag)

***

### data()

> **data**(): `Record`\<`string`, `any`>

Defined in: [src/lib/logger/components/toolCall.ts:155](https://github.com/maximhq/maxim-js/blob/main/src/lib/logger/components/toolCall.ts#L155)

Returns the complete data representation of this tool call.

#### Returns

`Record`\<`string`, `any`>

Tool call data.

#### Example

```ts theme={null}
const toolData = toolCall.data();
```

#### Overrides

[`BaseContainer`](./BaseContainer).[`data`](./BaseContainer#data)

***

### end()

> **end**(): `void`

Defined in: [src/lib/logger/components/base.ts:163](https://github.com/maximhq/maxim-js/blob/main/src/lib/logger/components/base.ts#L163)

Marks this container as ended and records the end timestamp.

#### Returns

`void`

void

#### Example

```ts theme={null}
// End a container when processing is complete
container.end();
```

#### Inherited from

[`BaseContainer`](./BaseContainer).[`end`](./BaseContainer#end)

***

### error()

> **error**(`error`): `void`

Defined in: [src/lib/logger/components/toolCall.ts:128](https://github.com/maximhq/maxim-js/blob/main/src/lib/logger/components/toolCall.ts#L128)

Records an error that occurred during this tool call and ends it.

#### Parameters

##### error

[`ToolCallError`](../interfaces/ToolCallError)

Error information including message, code, and type

#### Returns

`void`

void

#### Example

```ts theme={null}
toolCall.error({
  message: 'Database connection failed',
  code: 'DB_CONNECTION_ERROR',
  type: 'DatabaseError'
});
```

***

### result()

> **result**(`result`): `void`

Defined in: [src/lib/logger/components/toolCall.ts:96](https://github.com/maximhq/maxim-js/blob/main/src/lib/logger/components/toolCall.ts#L96)

Records the successful result of this tool call and ends it.

#### Parameters

##### result

`string`

The result returned by the tool as a string

#### Returns

`void`

void

#### Example

```ts theme={null}
toolCall.result(JSON.stringify({
  userId: '12345',
  name: 'John Doe',
  email: 'john@example.com'
}));
```

***

### addMetadata\_()

> `static` **addMetadata\_**(`writer`, `entity`, `id`, `metadata`): `void`

Defined in: [src/lib/logger/components/base.ts:144](https://github.com/maximhq/maxim-js/blob/main/src/lib/logger/components/base.ts#L144)

Static method to add metadata to any container by ID.

#### Parameters

##### writer

[`LogWriter`](./LogWriter)

The log writer instance

##### entity

[`Entity`](../enumerations/Entity)

The entity type

##### id

`string`

The container ID

##### metadata

`Record`\<`string`, `unknown`>

The metadata to add

#### Returns

`void`

void

#### Inherited from

[`BaseContainer`](./BaseContainer).[`addMetadata_`](./BaseContainer#addmetadata_)

***

### addTag\_()

> `static` **addTag\_**(`writer`, `entity`, `id`, `key`, `value`): `void`

Defined in: [src/lib/logger/components/base.ts:108](https://github.com/maximhq/maxim-js/blob/main/src/lib/logger/components/base.ts#L108)

Static method to add a tag to any container by ID.

#### Parameters

##### writer

[`LogWriter`](./LogWriter)

The log writer instance

##### entity

[`Entity`](../enumerations/Entity)

The entity type

##### id

`string`

The container ID

##### key

`string`

The tag key

##### value

`string`

The tag value

#### Returns

`void`

void

#### Inherited from

[`BaseContainer`](./BaseContainer).[`addTag_`](./BaseContainer#addtag_)

***

### end\_()

> `static` **end\_**(`writer`, `entity`, `id`, `data?`): `void`

Defined in: [src/lib/logger/components/base.ts:177](https://github.com/maximhq/maxim-js/blob/main/src/lib/logger/components/base.ts#L177)

Static method to end any container by ID.

#### Parameters

##### writer

[`LogWriter`](./LogWriter)

The log writer instance

##### entity

[`Entity`](../enumerations/Entity)

The entity type

##### id

`string`

The container ID

##### data?

`any`

Optional additional data to include with the end event

#### Returns

`void`

void

#### Inherited from

[`BaseContainer`](./BaseContainer).[`end_`](./BaseContainer#end_)

***

### error\_()

> `static` **error\_**(`writer`, `id`, `error`): `void`

Defined in: [src/lib/logger/components/toolCall.ts:141](https://github.com/maximhq/maxim-js/blob/main/src/lib/logger/components/toolCall.ts#L141)

Static method to record an error for any tool call by ID.

#### Parameters

##### writer

[`LogWriter`](./LogWriter)

The log writer instance

##### id

`string`

The tool call ID

##### error

[`ToolCallError`](../interfaces/ToolCallError)

Error information

#### Returns

`void`

void

***

### result\_()

> `static` **result\_**(`writer`, `id`, `result`): `void`

Defined in: [src/lib/logger/components/toolCall.ts:109](https://github.com/maximhq/maxim-js/blob/main/src/lib/logger/components/toolCall.ts#L109)

Static method to record a result for any tool call by ID.

#### Parameters

##### writer

[`LogWriter`](./LogWriter)

The log writer instance

##### id

`string`

The tool call ID

##### result

`string`

The result returned by the tool

#### Returns

`void`

void


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.