Skip to content
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
11 changes: 10 additions & 1 deletion AuthorAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ public class AuthorAgent : IAuthorAgent

private readonly ILogger<AuthorAgent> _logger;

// Per-call output-token cap, applied on each RunAsync to bound cost.
private readonly int? _maxOutputTokens;

public AuthorAgent(IChatClient llm, ChatOptions chatOptions, ILogger<AuthorAgent> logger)
{
_logger = logger;
_maxOutputTokens = chatOptions.MaxOutputTokens;

_agent = new ChatClientAgent(llm, new ChatClientAgentOptions
{
Expand Down Expand Up @@ -60,7 +64,12 @@ public async Task<string> InvokeAsync(ResearchState state)

try
{
AgentResponse response = await _agent.RunAsync(message);
// Cap per-call output tokens so a single turn can't blow the cost budget.
ChatClientAgentRunOptions runOptions = new(new ChatOptions
{
MaxOutputTokens = _maxOutputTokens,
});
AgentResponse response = await _agent.RunAsync(message, options: runOptions);
string content = response.Text;
return !string.IsNullOrEmpty(content) ? content : "Draft in progress...";
}
Expand Down
11 changes: 10 additions & 1 deletion BloggerAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ public class BloggerAgent : IBloggerAgent

private readonly ILogger<BloggerAgent> _logger;

// Per-call output-token cap, applied on each RunAsync to bound cost.
private readonly int? _maxOutputTokens;

public BloggerAgent(IChatClient llm, ChatOptions chatOptions, ILogger<BloggerAgent> logger)
{
_logger = logger;
_maxOutputTokens = chatOptions.MaxOutputTokens;

_agent = new ChatClientAgent(llm, new ChatClientAgentOptions
{
Expand Down Expand Up @@ -110,8 +114,13 @@ public async Task<BloggerDecision> InvokeAsync(ResearchState state)

try
{
// Cap per-call output tokens so a single turn can't blow the cost budget.
ChatClientAgentRunOptions runOptions = new(new ChatOptions
{
MaxOutputTokens = _maxOutputTokens,
});
AgentResponse<BloggerDecision> response =
await _agent.RunAsync<BloggerDecision>(stateSummary, serializerOptions: _jsonOptions);
await _agent.RunAsync<BloggerDecision>(stateSummary, options: runOptions, serializerOptions: _jsonOptions);

BloggerDecision decision = response.Result;
if (decision is not null && !string.IsNullOrEmpty(decision.NextStep))
Expand Down
11 changes: 10 additions & 1 deletion ResearcherAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ public class ResearcherAgent : IResearcherAgent

private readonly ILogger<ResearcherAgent> _logger;

// Per-call output-token cap, applied on each RunAsync to bound cost.
private readonly int? _maxOutputTokens;

public ResearcherAgent(IChatClient llm, ChatOptions chatOptions, AIFunction tavilyTool, ILogger<ResearcherAgent> logger)
{
_logger = logger;
_maxOutputTokens = chatOptions.MaxOutputTokens;

_agent = new ChatClientAgent(llm, new ChatClientAgentOptions
{
Expand Down Expand Up @@ -59,7 +63,12 @@ public async Task<string> InvokeAsync(string query)
{
// A single agent run: the model may call tavily_search one or more
// times, read the results, and return a concise summary as its text.
AgentResponse response = await _agent.RunAsync(query);
// Cap per-call output tokens so a single turn can't blow the cost budget.
ChatClientAgentRunOptions runOptions = new(new ChatOptions
{
MaxOutputTokens = _maxOutputTokens,
});
AgentResponse response = await _agent.RunAsync(query, options: runOptions);
string summary = response.Text;

return !string.IsNullOrEmpty(summary)
Expand Down
11 changes: 10 additions & 1 deletion ReviewerAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ public class ReviewerAgent : IReviewerAgent

private readonly ILogger<ReviewerAgent> _logger;

// Per-call output-token cap, applied on each RunAsync to bound cost.
private readonly int? _maxOutputTokens;

public ReviewerAgent(IChatClient llm, ChatOptions chatOptions, ILogger<ReviewerAgent> logger)
{
_logger = logger;
_maxOutputTokens = chatOptions.MaxOutputTokens;

_agent = new ChatClientAgent(llm, new ChatClientAgentOptions
{
Expand Down Expand Up @@ -62,7 +66,12 @@ public async Task<string> InvokeAsync(ResearchState state)

try
{
AgentResponse response = await _agent.RunAsync(message);
// Cap per-call output tokens so a single turn can't blow the cost budget.
ChatClientAgentRunOptions runOptions = new(new ChatOptions
{
MaxOutputTokens = _maxOutputTokens,
});
AgentResponse response = await _agent.RunAsync(message, options: runOptions);
string content = response.Text;
return !string.IsNullOrEmpty(content) ? content : "APPROVED";
Comment on lines +74 to 76
}
Expand Down