Skip to content

Tools enhancement and Agents implementation #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified build/GenerativeAI.zip
Binary file not shown.
256 changes: 256 additions & 0 deletions docs/automation.generativeai.agents.agent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
# Agent

Namespace: Automation.GenerativeAI.Agents

Represents an Agent that can perform certain actions to accomplish given objective.

```csharp
public abstract class Agent
```

Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [Agent](./automation.generativeai.agents.agent.md)

## Properties

### **Name**

Name of the Agent

```csharp
public string Name { get; private set; }
```

#### Property Value

[String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>

### **Description**

Description of the agent

```csharp
public string Description { get; set; }
```

#### Property Value

[String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>

## Methods

### **WithDescription(String)**

Sets description

```csharp
public Agent WithDescription(string description)
```

#### Parameters

`description` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
Description of the agent.

#### Returns

[Agent](./automation.generativeai.agents.agent.md)<br>
This Agent

### **WithTools(IEnumerable&lt;IFunctionTool&gt;)**

Sets a list of allowed tools for agent to use.

```csharp
public Agent WithTools(IEnumerable<IFunctionTool> tools)
```

#### Parameters

`tools` [IEnumerable&lt;IFunctionTool&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1)<br>
List of tools

#### Returns

[Agent](./automation.generativeai.agents.agent.md)<br>
This Agent

### **WithLanguageModel(ILanguageModel)**

Sets language model to the agent

```csharp
public Agent WithLanguageModel(ILanguageModel languageModel)
```

#### Parameters

`languageModel` [ILanguageModel](./automation.generativeai.interfaces.ilanguagemodel.md)<br>
Language model for agent to perform certain tasks

#### Returns

[Agent](./automation.generativeai.agents.agent.md)<br>
This Agent

### **WithTemperature(Double)**

Sets the temperature parameter to agent to define the creativity.

```csharp
public Agent WithTemperature(double temperature)
```

#### Parameters

`temperature` [Double](https://docs.microsoft.com/en-us/dotnet/api/system.double)<br>
A value between 0 and 1 to define creativity

#### Returns

[Agent](./automation.generativeai.agents.agent.md)<br>
This Agent

### **WithMaxAllowedSteps(Int32)**

Sets the maximum number of steps this agent can execute.

```csharp
public Agent WithMaxAllowedSteps(int maxAllowedSteps)
```

#### Parameters

`maxAllowedSteps` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br>
Maximum number of steps that can be executed.

#### Returns

[Agent](./automation.generativeai.agents.agent.md)<br>
This Agent

### **GetNextActionAsync(List&lt;ChatMessage&gt;)**

Provides a next agent action based on the given message history.

```csharp
protected abstract Task<AgentAction> GetNextActionAsync(List<ChatMessage> messages)
```

#### Parameters

`messages` [List&lt;ChatMessage&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1)<br>
History of messages as a list

#### Returns

[Task&lt;AgentAction&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1)<br>
AgentAction

### **ExecuteAsync(String)**

Executes the given objective

```csharp
public Task<AgentAction> ExecuteAsync(string objective)
```

#### Parameters

`objective` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The detailed objective for agent to achieve.

#### Returns

[Task&lt;AgentAction&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1)<br>
FinishAction if objective is met or got an error. It may return AgentAction if the
tool associated with the action can't be executed. It provides clients to execute the
action logic and then call UpdateToolResponseAsync to proceed further with execution.

### **UpdateAgentActionResponseAsync(String, String)**

Called by the client to update the tool's execution result with the agent, if the tool
corresponding to the agent action was executed by client.

```csharp
public Task<AgentAction> UpdateAgentActionResponseAsync(string toolName, string output)
```

#### Parameters

`toolName` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
Name of the tool that executed

`output` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
Output of the tool.

#### Returns

[Task&lt;AgentAction&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1)<br>
FinishAction if objective is met or got an error. AgentAction if it is
required to be executed by client.

### **LoadSystemPrompt(String, String, String)**

The derived class implements this method to provide a system prompt text for the language model.

```csharp
protected abstract string LoadSystemPrompt(string username, string date, string workingdir)
```

#### Parameters

`username` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
Name of the user interactive with agent

`date` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
Today's date

`workingdir` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
Full path of the working directory

#### Returns

[String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
System prompt text

### **Create(String, String, AgentType)**

Creates an agent

```csharp
public static Agent Create(string name, string workingdir, AgentType type)
```

#### Parameters

`name` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
A unique name of the agent

`workingdir` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
Full path of the working directory

`type` [AgentType](./automation.generativeai.agents.agenttype.md)<br>
Type of the agent to create

#### Returns

[Agent](./automation.generativeai.agents.agent.md)<br>
Agent

### **MessgeFromResponse(LLMResponse)**

Converts the LLMResponse to ChatMessage

```csharp
protected internal static ChatMessage MessgeFromResponse(LLMResponse response)
```

#### Parameters

`response` [LLMResponse](./automation.generativeai.interfaces.llmresponse.md)<br>
A response returned from the language model.

#### Returns

[ChatMessage](./automation.generativeai.interfaces.chatmessage.md)<br>
ChatMessage
98 changes: 98 additions & 0 deletions docs/automation.generativeai.agents.agentaction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# AgentAction

Namespace: Automation.GenerativeAI.Agents

Represents agent action that can be executed as current step. It holdes a tool
and execution context so that the tool can be executed.

```csharp
public class AgentAction
```

Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [AgentAction](./automation.generativeai.agents.agentaction.md)

## Properties

### **Parameters**

List of input parameters required for the tool/action.

```csharp
public IEnumerable<string> Parameters { get; }
```

#### Property Value

[IEnumerable&lt;String&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1)<br>

### **Tool**

Gets the tool that this action can execute.

```csharp
public IFunctionTool Tool { get; protected set; }
```

#### Property Value

[IFunctionTool](./automation.generativeai.interfaces.ifunctiontool.md)<br>

### **Thought**

Gets the reasoning for this action.

```csharp
public string Thought { get; set; }
```

#### Property Value

[String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>

### **ExecutionContext**

Execution context for this action

```csharp
public ExecutionContext ExecutionContext { get; private set; }
```

#### Property Value

[ExecutionContext](./automation.generativeai.interfaces.executioncontext.md)<br>

## Constructors

### **AgentAction(IFunctionTool, ExecutionContext, String)**

Constructor

```csharp
public AgentAction(IFunctionTool tool, ExecutionContext executionContext, string thought)
```

#### Parameters

`tool` [IFunctionTool](./automation.generativeai.interfaces.ifunctiontool.md)<br>
The tool this action can execute.

`executionContext` [ExecutionContext](./automation.generativeai.interfaces.executioncontext.md)<br>
Execution context to execute the tool.

`thought` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br>
The reasoning of the thought for this action.

## Methods

### **ExecuteAsync()**

Executes the given tool asynchronously.

```csharp
public Task<string> ExecuteAsync()
```

#### Returns

[Task&lt;String&gt;](https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1)<br>
Output string returned from the tool after execution.
18 changes: 18 additions & 0 deletions docs/automation.generativeai.agents.agenttype.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# AgentType

Namespace: Automation.GenerativeAI.Agents

Represents a type of Agent

```csharp
public enum AgentType
```

Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [ValueType](https://docs.microsoft.com/en-us/dotnet/api/system.valuetype) → [Enum](https://docs.microsoft.com/en-us/dotnet/api/system.enum) → [AgentType](./automation.generativeai.agents.agenttype.md)<br>
Implements [IComparable](https://docs.microsoft.com/en-us/dotnet/api/system.icomparable), [IFormattable](https://docs.microsoft.com/en-us/dotnet/api/system.iformattable), [IConvertible](https://docs.microsoft.com/en-us/dotnet/api/system.iconvertible)

## Fields

| Name | Value | Description |
| --- | --: | --- |
| FunctionAgent | 0 | Represents an agent that makes use of OpenAI Function call capability. |
Loading