Add a C# DLL Tool
Expose high-trust compiled C# assemblies, native .NET APIs, and third-party SDKs directly to the Buffaly agent runtime. Learn how to write structured tools, configure imports, and project them as discoverable agent actions.
Choosing the right capability boundary
While many agent workflows can be expressed as prompt guidance, deterministic logic (like system commands, database reads, file compression, and API calls) should be compiled in C#. Use this guide to choose the optimal abstraction:
| Scenario | Recommended Choice | Why |
|---|---|---|
| Stateless, deterministic process logic | C# DLL Tool | Compiled C# runs fast, has strict timeouts, and guarantees type safety. |
| Stable review, drafting, or checklist rules | Prompt Skill | Easier to iterate on using conversational guidance than hard code. |
| Custom script that combines multiple tools | ProtoScript Action | Organizes high-level agent logic and loops within the active project. |
| System with configuration, lifecycle, or state | Service Boundary | The service manages active connections and configurations. |
Repository tool architecture
In the Buffaly codebase, tools are organized into specific, testable .NET projects under the naming scheme Buffaly.Agent.Tools.*.
These projects target .NET 9 and compile into independent DLL assemblies:
FileSystem Tools Compiled
Static file operations, Ripgrep integrations, and range reading. Assembly: Buffaly.Agent.Tools.FileSystem.dll.
System Operations Compiled
Low-overhead command-line and fast PowerShell 7 process hosting. Assembly: Buffaly.Agent.Tools.Process.dll.
Secrets Vault Compiled
Resolves offline database passwords and API tokens securely. Assembly: Buffaly.Agent.Tools.Secrets.dll.
Relational DB Compiled
Performs database schemas audits and query testing under SQL Server. Assembly: Buffaly.Agent.Tools.SqlServer.dll.
Expected C# class structure
Keep your C# class helper static, highly focused, and type-safe. Avoid silent exceptions and return clear diagnostic strings:
namespace Buffaly.Agent.Tools.MyDomain;
public static class MyDomainTools
{
public static string DescribeConfiguredThing(string name)
{
if (string.IsNullOrWhiteSpace(name))
{
return "Error: name parameter is required.";
}
// Execute deterministic C# SDK, command, or filesystem logic
return "Configured thing: " + name.Trim();
}
}
Projecting C# into ProtoScript actions
To let the agent semantically discover and invoke your compiled helper method, bind the binary to your ProtoScript project:
Add reference and import keys inside content/projects/OpsAgent/Imports.pts to load the class structure:
reference "lib/Buffaly.Agent.Tools.MyDomain.dll" Buffaly.Agent.Tools.MyDomain; import Buffaly.Agent.Tools.MyDomain Buffaly.Agent.Tools.MyDomain.MyDomainTools MyDomainTools;
Create a wrapped skill action. Use semantic InfinitivePhrase decorators so the agent can discover it by intent:
[SemanticProgram.InfinitivePhrase("to describe a configured thing")]
prototype ToDescribeConfiguredThing extends MyDomainSkillAction
{
Description = @"Describe one configured thing by name using the MyDomain C# tool.";
function Execute(string name) : String
{
return MyDomainTools.DescribeConfiguredThing(name);
}
}
The easiest way: ask Buffaly to create it
You do not need to perform every edit manually. Ask Buffaly to inspect existing tool projects first, create the smallest matching compiled helper, wrap it with a ProtoScript action, validate discovery, verify encoding-safe examples, and commit only intentional files.
Buffaly.Agent.Tools.* projects first, wrap it with a ProtoScript action, build, validate discovery, and commit only intentional files."Recommended implementation workflow
Follow this process to add or extend a compiled capability in your local workspace:
Write your C# static tool, target .NET 9 in your csproj, compile it, and place the output DLL in the project's library folder.
Add reference and import keys under Imports.pts, and implement a prototype action with a semantic phrase.
Compile the ProtoScript project, reload the runtime environment, and ask the agent to semantically discover your action.
Operational validation checklist
Before finalizing your custom tool development, confirm that all layers are properly integrated and healthy:
content/projects/OpsAgent/lib/.Troubleshooting
Execute(...) method, not from a raw C# method alone.reference line, and check for missing dependent DLLs.