|
| 1 | +# Agent |
| 2 | + |
| 3 | +Namespace: Automation.GenerativeAI.Agents |
| 4 | + |
| 5 | +Represents an Agent that can perform certain actions to accomplish given objective. |
| 6 | + |
| 7 | +```csharp |
| 8 | +public abstract class Agent |
| 9 | +``` |
| 10 | + |
| 11 | +Inheritance [Object](https://docs.microsoft.com/en-us/dotnet/api/system.object) → [Agent](./automation.generativeai.agents.agent.md) |
| 12 | +
|
| 13 | +## Properties |
| 14 | + |
| 15 | +### **Name** |
| 16 | + |
| 17 | +Name of the Agent |
| 18 | + |
| 19 | +```csharp |
| 20 | +public string Name { get; private set; } |
| 21 | +``` |
| 22 | + |
| 23 | +#### Property Value |
| 24 | + |
| 25 | +[String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br> |
| 26 | +
|
| 27 | +### **Description** |
| 28 | + |
| 29 | +Description of the agent |
| 30 | + |
| 31 | +```csharp |
| 32 | +public string Description { get; set; } |
| 33 | +``` |
| 34 | + |
| 35 | +#### Property Value |
| 36 | + |
| 37 | +[String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br> |
| 38 | +
|
| 39 | +## Methods |
| 40 | + |
| 41 | +### **WithDescription(String)** |
| 42 | + |
| 43 | +Sets description |
| 44 | + |
| 45 | +```csharp |
| 46 | +public Agent WithDescription(string description) |
| 47 | +``` |
| 48 | + |
| 49 | +#### Parameters |
| 50 | + |
| 51 | +`description` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br> |
| 52 | +Description of the agent. |
| 53 | + |
| 54 | +#### Returns |
| 55 | + |
| 56 | +[Agent](./automation.generativeai.agents.agent.md)<br> |
| 57 | +This Agent |
| 58 | + |
| 59 | +### **WithTools(IEnumerable<IFunctionTool>)** |
| 60 | + |
| 61 | +Sets a list of allowed tools for agent to use. |
| 62 | + |
| 63 | +```csharp |
| 64 | +public Agent WithTools(IEnumerable<IFunctionTool> tools) |
| 65 | +``` |
| 66 | + |
| 67 | +#### Parameters |
| 68 | + |
| 69 | +`tools` [IEnumerable<IFunctionTool>](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1)<br> |
| 70 | +List of tools |
| 71 | + |
| 72 | +#### Returns |
| 73 | + |
| 74 | +[Agent](./automation.generativeai.agents.agent.md)<br> |
| 75 | +This Agent |
| 76 | + |
| 77 | +### **WithLanguageModel(ILanguageModel)** |
| 78 | + |
| 79 | +Sets language model to the agent |
| 80 | + |
| 81 | +```csharp |
| 82 | +public Agent WithLanguageModel(ILanguageModel languageModel) |
| 83 | +``` |
| 84 | + |
| 85 | +#### Parameters |
| 86 | + |
| 87 | +`languageModel` [ILanguageModel](./automation.generativeai.interfaces.ilanguagemodel.md)<br> |
| 88 | +Language model for agent to perform certain tasks |
| 89 | + |
| 90 | +#### Returns |
| 91 | + |
| 92 | +[Agent](./automation.generativeai.agents.agent.md)<br> |
| 93 | +This Agent |
| 94 | + |
| 95 | +### **WithTemperature(Double)** |
| 96 | + |
| 97 | +Sets the temperature parameter to agent to define the creativity. |
| 98 | + |
| 99 | +```csharp |
| 100 | +public Agent WithTemperature(double temperature) |
| 101 | +``` |
| 102 | + |
| 103 | +#### Parameters |
| 104 | + |
| 105 | +`temperature` [Double](https://docs.microsoft.com/en-us/dotnet/api/system.double)<br> |
| 106 | +A value between 0 and 1 to define creativity |
| 107 | + |
| 108 | +#### Returns |
| 109 | + |
| 110 | +[Agent](./automation.generativeai.agents.agent.md)<br> |
| 111 | +This Agent |
| 112 | + |
| 113 | +### **WithMaxAllowedSteps(Int32)** |
| 114 | + |
| 115 | +Sets the maximum number of steps this agent can execute. |
| 116 | + |
| 117 | +```csharp |
| 118 | +public Agent WithMaxAllowedSteps(int maxAllowedSteps) |
| 119 | +``` |
| 120 | + |
| 121 | +#### Parameters |
| 122 | + |
| 123 | +`maxAllowedSteps` [Int32](https://docs.microsoft.com/en-us/dotnet/api/system.int32)<br> |
| 124 | +Maximum number of steps that can be executed. |
| 125 | + |
| 126 | +#### Returns |
| 127 | + |
| 128 | +[Agent](./automation.generativeai.agents.agent.md)<br> |
| 129 | +This Agent |
| 130 | + |
| 131 | +### **GetNextActionAsync(List<ChatMessage>)** |
| 132 | + |
| 133 | +Provides a next agent action based on the given message history. |
| 134 | + |
| 135 | +```csharp |
| 136 | +protected abstract Task<AgentAction> GetNextActionAsync(List<ChatMessage> messages) |
| 137 | +``` |
| 138 | + |
| 139 | +#### Parameters |
| 140 | + |
| 141 | +`messages` [List<ChatMessage>](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1)<br> |
| 142 | +History of messages as a list |
| 143 | + |
| 144 | +#### Returns |
| 145 | + |
| 146 | +[Task<AgentAction>](https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1)<br> |
| 147 | +AgentAction |
| 148 | + |
| 149 | +### **ExecuteAsync(String)** |
| 150 | + |
| 151 | +Executes the given objective |
| 152 | + |
| 153 | +```csharp |
| 154 | +public Task<AgentAction> ExecuteAsync(string objective) |
| 155 | +``` |
| 156 | + |
| 157 | +#### Parameters |
| 158 | + |
| 159 | +`objective` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br> |
| 160 | +The detailed objective for agent to achieve. |
| 161 | + |
| 162 | +#### Returns |
| 163 | + |
| 164 | +[Task<AgentAction>](https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1)<br> |
| 165 | +FinishAction if objective is met or got an error. It may return AgentAction if the |
| 166 | + tool associated with the action can't be executed. It provides clients to execute the |
| 167 | + action logic and then call UpdateToolResponseAsync to proceed further with execution. |
| 168 | + |
| 169 | +### **UpdateAgentActionResponseAsync(String, String)** |
| 170 | + |
| 171 | +Called by the client to update the tool's execution result with the agent, if the tool |
| 172 | + corresponding to the agent action was executed by client. |
| 173 | + |
| 174 | +```csharp |
| 175 | +public Task<AgentAction> UpdateAgentActionResponseAsync(string toolName, string output) |
| 176 | +``` |
| 177 | + |
| 178 | +#### Parameters |
| 179 | + |
| 180 | +`toolName` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br> |
| 181 | +Name of the tool that executed |
| 182 | + |
| 183 | +`output` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br> |
| 184 | +Output of the tool. |
| 185 | + |
| 186 | +#### Returns |
| 187 | + |
| 188 | +[Task<AgentAction>](https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task-1)<br> |
| 189 | +FinishAction if objective is met or got an error. AgentAction if it is |
| 190 | + required to be executed by client. |
| 191 | + |
| 192 | +### **LoadSystemPrompt(String, String, String)** |
| 193 | + |
| 194 | +The derived class implements this method to provide a system prompt text for the language model. |
| 195 | + |
| 196 | +```csharp |
| 197 | +protected abstract string LoadSystemPrompt(string username, string date, string workingdir) |
| 198 | +``` |
| 199 | + |
| 200 | +#### Parameters |
| 201 | + |
| 202 | +`username` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br> |
| 203 | +Name of the user interactive with agent |
| 204 | + |
| 205 | +`date` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br> |
| 206 | +Today's date |
| 207 | + |
| 208 | +`workingdir` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br> |
| 209 | +Full path of the working directory |
| 210 | + |
| 211 | +#### Returns |
| 212 | + |
| 213 | +[String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br> |
| 214 | +System prompt text |
| 215 | + |
| 216 | +### **Create(String, String, AgentType)** |
| 217 | + |
| 218 | +Creates an agent |
| 219 | + |
| 220 | +```csharp |
| 221 | +public static Agent Create(string name, string workingdir, AgentType type) |
| 222 | +``` |
| 223 | + |
| 224 | +#### Parameters |
| 225 | + |
| 226 | +`name` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br> |
| 227 | +A unique name of the agent |
| 228 | + |
| 229 | +`workingdir` [String](https://docs.microsoft.com/en-us/dotnet/api/system.string)<br> |
| 230 | +Full path of the working directory |
| 231 | + |
| 232 | +`type` [AgentType](./automation.generativeai.agents.agenttype.md)<br> |
| 233 | +Type of the agent to create |
| 234 | + |
| 235 | +#### Returns |
| 236 | + |
| 237 | +[Agent](./automation.generativeai.agents.agent.md)<br> |
| 238 | +Agent |
| 239 | + |
| 240 | +### **MessgeFromResponse(LLMResponse)** |
| 241 | + |
| 242 | +Converts the LLMResponse to ChatMessage |
| 243 | + |
| 244 | +```csharp |
| 245 | +protected internal static ChatMessage MessgeFromResponse(LLMResponse response) |
| 246 | +``` |
| 247 | + |
| 248 | +#### Parameters |
| 249 | + |
| 250 | +`response` [LLMResponse](./automation.generativeai.interfaces.llmresponse.md)<br> |
| 251 | +A response returned from the language model. |
| 252 | + |
| 253 | +#### Returns |
| 254 | + |
| 255 | +[ChatMessage](./automation.generativeai.interfaces.chatmessage.md)<br> |
| 256 | +ChatMessage |
0 commit comments