Many AI applications start with a simple chat interface.
The user sends a message, the application sends it to an AI model, and the model returns a response.
User
|
v
Application
|
v
AI Model
|
v
ResponseThis works well for basic question-and-answer scenarios. However, modern AI applications often need to do more than generate text.
An AI agent may need to ask follow-up questions, call tools, inspect results, make decisions, wait for user input, and continue the task based on the response.
That changes the application from a one-way chatbot into an interactive agent workflow.
In C#, this can be implemented by treating the agent as an ongoing process with state, tools, decisions, and interaction points instead of simply calling a model for every message.
Chatbot vs Interactive Agent
A traditional chatbot generally follows a request-response pattern:
User Question
|
v
AI Model
|
v
AI ResponseAn interactive agent can follow a more dynamic flow:
User Request
|
v
Agent
|
+---- Ask Question ----> User
| |
|<------ Answer ----------+
|
+---- Call Tool
|
+---- Analyze Result
|
+---- Ask Another Question
|
v
Final ActionThe agent is no longer just generating a response.
It is participating in a process.
For example, instead of asking:
User:
Book a hotel in Delhi.and immediately generating text, an interactive agent might ask:
Agent:
What dates are you traveling?
User:
October 10 to October 12.
Agent:
How many guests?
User:
Two.
Agent:
I found several matching options. Which price range should I use?The application needs to maintain context throughout this interaction.
What Makes an Agent Interactive?
An interactive agent generally has several capabilities:
Conversation state
User input handling
Tool calling
Conditional decisions
Follow-up questions
Workflow state
Human approval when required
Error handling
Long-running execution
A useful mental model is:
+----------------+
| Agent |
+-------+--------+
|
+--------------+--------------+
| | |
v v v
User Input Tools Memory
| | |
+--------------+--------------+
|
v
Decision
|
+----------+----------+
| |
v v
Ask User Again ContinueThis structure allows the agent to react to the situation rather than always producing a final answer immediately.
Managing Conversation State in C#
The first requirement is maintaining state between interactions.
A simple state model might look like this:
public sealed class AgentSession
{
public string SessionId { get; init; } = string.Empty;
public string UserId { get; init; } = string.Empty;
public List<ChatMessage> Messages { get; } = [];
public string? CurrentTask { get; set; }
public string? PendingQuestion { get; set; }
}The important part is that the state should be associated with a specific session or workflow.
For example:
Session ID: SESSION-1001
User ID: USER-42
Current Task: Generate monthly report
Pending Question: Which department?When the user responds, the application can retrieve the session and continue from the current state.
Asking Follow-Up Questions
A useful agent should not guess when important information is missing.
Consider a report-generation request:
User:
Create a sales report.The agent may need additional information:
Agent:
Which period should I use?The application can represent this as a pending interaction:
public sealed class PendingInteraction
{
public string InteractionId { get; init; } = string.Empty;
public string SessionId { get; init; } = string.Empty;
public string Question { get; init; } = string.Empty;
public string ExpectedInput { get; init; } = string.Empty;
}The UI can display the question and send the user's answer back to the application.
The agent then continues instead of starting a completely new task.
Separating the Agent From the User Interface
A common architectural mistake is putting agent logic directly inside the web or mobile UI.
Instead, keep the interaction layer separate:
Web / Mobile UI
|
v
Agent API
|
v
Agent Orchestrator
|
+---- Memory
|
+---- Tools
|
+---- Workflow State
|
v
AI ModelFor example, an ASP.NET Core endpoint could receive the user's message:
[ApiController]
[Route("api/agent")]
public class AgentController : ControllerBase
{
private readonly IAgentService _agentService;
public AgentController(IAgentService agentService)
{
_agentService = agentService;
}
[HttpPost("message")]
public async Task<IActionResult> SendMessage(
AgentMessageRequest request,
CancellationToken cancellationToken)
{
var response = await _agentService.ProcessAsync(
request,
cancellationToken);
return Ok(response);
}
}The controller should not contain the agent's reasoning or workflow logic.
That belongs in a dedicated service or orchestration layer.
Returning an Interaction Instead of a Final Answer
An interactive agent does not always need to return a completed response.
A response model can explicitly represent the next action:
public enum AgentResponseType
{
Message,
Question,
ToolCall,
Completed,
Failed
}Then:
public sealed class AgentResponse
{
public AgentResponseType Type { get; init; }
public string? Message { get; init; }
public string? InteractionId { get; init; }
}Now the client can determine what to do.
For example:
Type: Question
Message:
Which database should I use?
InteractionId:
INT-204The UI can display the question and wait for the user's response.
This is more reliable than trying to infer application state from plain text.
Tool Calling Makes Agents More Useful
Interactive agents become more powerful when they can use tools.
Suppose a user asks:
How many orders were created today?The agent can decide that it needs database information.
Conceptually:
User
|
v
Agent
|
+--> Need order data
|
v
Database Tool
|
v
Order Count
|
v
Agent
|
v
UserA tool can be represented through an interface:
public interface IOrderTool
{
Task<int> GetTodayOrderCountAsync(
CancellationToken cancellationToken);
}
Join the conversation! Your thoughts help the community grow.