> For the complete documentation index, see [llms.txt](https://docs.wisej.com/ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wisej.com/ai/components/api/smarttool/wisej.ai.smarttool.toolcontext.md).

# SmartTool.ToolContext

Namespace: **Wisej.AI**

Assembly: **Wisej.AI** (3.5.0.0)

Represents the context in which a smart tool operates, providing properties and methods to manage tool execution.

{% tabs %}
{% tab title="C#" %}

```csharp
public class ToolContext
```

{% endtab %}

{% tab title="VB.NET" %}

```visual-basic
Public Class ToolContext
```

{% endtab %}
{% endtabs %}

The `ToolContext` class encapsulates the state and behavior required to execute a smart tool, including its arguments, session, and endpoint.

## Constructors

### ![](/files/ptrKjmmRoQB76pvrIqh0) ToolContext()

Initializes a new instance of [ToolContext](/ai/components/api/smarttool/wisej.ai.smarttool.toolcontext.md).

## Properties

### ![](/files/ptrKjmmRoQB76pvrIqh0) Abort

[Boolean](https://docs.microsoft.com/dotnet/api/system.boolean): Gets a value indicating whether the tool execution should be aborted.

### ![](/files/ptrKjmmRoQB76pvrIqh0) Arguments

[Dictionary\<String, Object>](https://docs.microsoft.com/dotnet/api/system.collections.generic.dictionary-2): Gets the arguments for the tool execution.

### ![](/files/ptrKjmmRoQB76pvrIqh0) Endpoint

[SmartEndpoint](/ai/components/api/smartendpoint.md): Gets the endpoint associated with the tool context.

### ![](/files/ptrKjmmRoQB76pvrIqh0) Id

[String](https://docs.microsoft.com/dotnet/api/system.string): Gets the unique identifier for the tool context.

### ![](/files/ptrKjmmRoQB76pvrIqh0) Iteration

[Int32](https://docs.microsoft.com/dotnet/api/system.int32): Gets the current iteration count for the tool execution.

### ![](/files/ptrKjmmRoQB76pvrIqh0) ReturnValue

[Object](https://docs.microsoft.com/dotnet/api/system.object): Gets or sets the return value of the tool execution.

### ![](/files/ptrKjmmRoQB76pvrIqh0) Session

[SmartSession](/ai/components/api/smartsession.md): Gets the session associated with the tool context.

### ![](/files/ptrKjmmRoQB76pvrIqh0) Tool

[SmartTool](/ai/components/api/smarttool.md): Gets the tool associated with the context.

## Methods

### ![](/files/ptrKjmmRoQB76pvrIqh0) Invoke()

Invokes the tool synchronously.

**Returns:** [Object](https://docs.microsoft.com/dotnet/api/system.object). The result of the tool invocation.

### ![](/files/ptrKjmmRoQB76pvrIqh0) InvokeAsync(session)

Invokes the tool asynchronously.

| Parameter   | Type                                               | Description                    |
| ----------- | -------------------------------------------------- | ------------------------------ |
| **session** | [SmartSession](/ai/components/api/smartsession.md) | The session invoking the tool. |

**Returns:** [Task](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task). A task representing the asynchronous operation.

This method handles exceptions and manages the tool invocation lifecycle, including raising events before and after invocation.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.wisej.com/ai/components/api/smarttool/wisej.ai.smarttool.toolcontext.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
