Skip to content

Commit 7f606a2

Browse files
authored
.NET: Add tweaks to .net agent skills (#4081)
* Add tweaks to .net agent skills * Address PR feedback
1 parent 6c32e86 commit 7f606a2

3 files changed

Lines changed: 98 additions & 41 deletions

File tree

dotnet/.github/skills/build-and-test/SKILL.md

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,83 @@ name: build-and-test
33
description: How to build and test .NET projects in the Agent Framework repository. Use this when verifying or testing changes.
44
---
55

6-
# Build and Test
7-
86
- Only **UnitTest** projects need to be run locally; IntegrationTests require external dependencies.
97
- See `../project-structure/SKILL.md` for project structure details.
108

11-
## Speeding Up Builds
9+
## Build, Test, and Lint Commands
10+
11+
```bash
12+
# From dotnet/ directory
13+
dotnet restore --tl:off # Restore dependencies for all projects
14+
dotnet build --tl:off # Build all projects
15+
dotnet test # Run all tests
16+
dotnet format # Auto-fix formatting for all projects
17+
18+
# Build/test/format a specific project (preferred for isolated/internal changes)
19+
dotnet build src/Microsoft.Agents.AI.<Package> --tl:off
20+
dotnet test tests/Microsoft.Agents.AI.<Package>.UnitTests
21+
dotnet format src/Microsoft.Agents.AI.<Package>
22+
23+
# Run a single test
24+
dotnet test --filter "FullyQualifiedName~Namespace.TestClassName.TestMethodName"
25+
26+
# Run unit tests only
27+
dotnet test --filter FullyQualifiedName\~UnitTests
28+
```
29+
30+
Use `--tl:off` when building to avoid flickering when running commands in the agent.
31+
32+
## Speeding Up Builds and Testing
1233

1334
The full solution is large. Use these shortcuts:
1435

1536
| Change type | What to do |
1637
|-------------|------------|
17-
| Internal logic | Build only the affected project and its `*.UnitTests` project. Fix issues, then build the full solution and run all unit tests. |
38+
| Isolated/Internal logic | Build only the affected project and its `*.UnitTests` project. Fix issues, then build the full solution and run all unit tests. |
1839
| Public API surface | Build the full solution and run all unit tests immediately. |
1940

2041
Example: Building a single code project for all target frameworks
2142

2243
```bash
23-
cd /workspaces/agent-framework/dotnet
24-
dotnet build ./src/Microsoft.Agents.AI.Abstractions/Microsoft.Agents.AI.Abstractions.csproj
44+
# From dotnet/ directory
45+
dotnet build ./src/Microsoft.Agents.AI.Abstractions
2546
```
2647

2748
Example: Building a single code project for just .NET 10.
2849

2950
```bash
30-
cd /workspaces/agent-framework/dotnet
31-
dotnet build ./src/Microsoft.Agents.AI.Abstractions/Microsoft.Agents.AI.Abstractions.csproj -f net10.0
51+
# From dotnet/ directory
52+
dotnet build ./src/Microsoft.Agents.AI.Abstractions -f net10.0
3253
```
3354

34-
Example: Running tests for a single project using .net 10.
55+
Example: Running tests for a single project using .NET 10.
3556

3657
```bash
37-
cd /workspaces/agent-framework/dotnet
38-
dotnet test ./tests/Microsoft.Agents.AI.Abstractions.UnitTests/Microsoft.Agents.AI.Abstractions.UnitTests.csproj -f net10.0
58+
# From dotnet/ directory
59+
dotnet test ./tests/Microsoft.Agents.AI.Abstractions.UnitTests -f net10.0
60+
```
61+
62+
Example: Running a single test in a specific project using .NET 10.
63+
Provide the full namespace, class name, and method name for the test you want to run:
64+
65+
```bash
66+
# From dotnet/ directory
67+
dotnet test ./tests/Microsoft.Agents.AI.Abstractions.UnitTests -f net10.0 --filter "FullyQualifiedName~Microsoft.Agents.AI.Abstractions.UnitTests.AgentRunOptionsTests.CloningConstructorCopiesProperties"
3968
```
4069

4170
### Multi-target framework tip
4271

43-
Most projects target multiple .NET frameworks. If the affected code does **not** use `#if` directives for framework-specific logic, pass `--framework net10.0` to speed up building and testing.
72+
Most projects target multiple .NET frameworks. If the affected code does **not** use `#if` directives for framework-specific logic, pass `-f net10.0` to speed up building and testing.
73+
74+
### Package Restore tip
75+
76+
`dotnet build` will try and restore packages for all projects on each build, which can be slow.
77+
Unless packages have been changed, or it's the first time building the solution, add `--no-restore` to the build command to skip this step and speed up builds.
78+
79+
Just remember to run `dotnet restore` after pulling changes, making changes to project references, or when building for the first time.
80+
81+
### Testing on Linux tip
82+
83+
Unit tests target both .NET Framework as well as .NET Core. When running on Linux, only the .NET Core tests can be run, as .NET Framework is not supported on Linux.
84+
85+
To run only the .NET Core tests, use the `-f net10.0` option with `dotnet test`.

dotnet/.github/skills/project-structure/SKILL.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,23 @@ description: Explains the project structure of the agent-framework .NET solution
55

66
# Agent Framework .NET Project Structure
77

8-
## Folders
8+
```
9+
dotnet/
10+
├── src/
11+
│ ├── Microsoft.Agents.AI/ # Core AI agent implementations
12+
│ ├── Microsoft.Agents.AI.Abstractions/ # Core AI agent abstractions
13+
│ ├── Microsoft.Agents.AI.A2A/ # Agent-to-Agent (A2A) provider
14+
│ ├── Microsoft.Agents.AI.OpenAI/ # OpenAI provider
15+
│ ├── Microsoft.Agents.AI.AzureAI/ # Azure AI Foundry Agents (v2) provider
16+
│ ├── Microsoft.Agents.AI.AzureAI.Persistent/ # Legacy Azure AI Foundry Agents (v1) provider
17+
│ ├── Microsoft.Agents.AI.Anthropic/ # Anthropic provider
18+
│ ├── Microsoft.Agents.AI.Workflows/ # Workflow orchestration
19+
│ └── ... # Other packages
20+
├── samples/ # Sample applications
21+
└── tests/ # Unit and integration tests
22+
```
23+
24+
## Main Folders
925

1026
| Folder | Contents |
1127
|--------|----------|

dotnet/AGENTS.md

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,28 @@ Instructions for AI coding agents working in the .NET codebase.
44

55
## Build, Test, and Lint Commands
66

7-
```bash
8-
# From dotnet/ directory
9-
dotnet build # Build all projects
10-
dotnet test # Run all tests
11-
dotnet format # Auto-fix formatting
7+
See `./.github/skills/build-and-test/SKILL.md` for detailed instructions on building, testing, and linting projects.
128

13-
# Build/test a specific project (preferred for isolated changes)
14-
dotnet build src/Microsoft.Agents.AI.<Package>
15-
dotnet test tests/Microsoft.Agents.AI.<Package>.UnitTests
16-
17-
# Run a single test
18-
dotnet test --filter "FullyQualifiedName~TestClassName.TestMethodName"
19-
```
9+
## Project Structure
2010

21-
**Note**: Changes to core packages (`Microsoft.Agents.AI`, `Microsoft.Agents.AI.Abstractions`) affect dependent projects - run checks across the entire solution. For isolated changes, build/test only the affected project to save time.
11+
See `./.github/skills/project-structure/SKILL.md` for an overview of the project structure.
2212

23-
## Project Structure
13+
### Core types
2414

25-
```
26-
dotnet/
27-
├── src/
28-
│ ├── Microsoft.Agents.AI/ # Core AI agent abstractions
29-
│ ├── Microsoft.Agents.AI.Abstractions/ # Shared abstractions and interfaces
30-
│ ├── Microsoft.Agents.AI.OpenAI/ # OpenAI provider
31-
│ ├── Microsoft.Agents.AI.AzureAI/ # Azure AI provider
32-
│ ├── Microsoft.Agents.AI.Anthropic/ # Anthropic provider
33-
│ ├── Microsoft.Agents.AI.Workflows/ # Workflow orchestration
34-
│ └── ... # Other packages
35-
├── samples/ # Sample applications
36-
└── tests/ # Unit and integration tests
37-
```
15+
- `AIAgent`: The abstract base class that all agents derive from, providing common methods for interacting with an agent.
16+
- `AgentSession`: The abstract base class that all agent sessions derive from, representing a conversation with an agent.
17+
- `ChatClientAgent`: An `AIAgent` implementation that uses an `IChatClient` to send messages to an AI provider and receive responses.
18+
- `IChatClient`: Interface for sending messages to an AI provider and receiving responses. Used by `ChatClientAgent` and implemented by provider-specific packages.
19+
- `FunctionInvokingChatClient`: Decorator for `IChatClient` that adds function invocation capabilities.
20+
- `AITool`: Represents a tool that an agent/AI provider can use, with metadata and an execution delegate.
21+
- `AIFunction`: A specific type of `AITool` that represents a local function the agent/AI provider can call, with parameters and return types defined.
22+
- `ChatMessage`: Represents a message in a conversation.
23+
- `AIContent`: Represents content in a message, which can be text, a function call, tool output and more.
3824

3925
### External Dependencies
4026

41-
The framework integrates with `Microsoft.Extensions.AI` and `Microsoft.Extensions.AI.Abstractions` (external NuGet packages) using types like `IChatClient`, `FunctionInvokingChatClient`, `AITool`, and `AIContent`.
27+
The framework integrates with `Microsoft.Extensions.AI` and `Microsoft.Extensions.AI.Abstractions` (external NuGet packages)
28+
using types like `IChatClient`, `FunctionInvokingChatClient`, `AITool`, `AIFunction`, `ChatMessage`, and `AIContent`.
4229

4330
## Key Conventions
4431

@@ -49,8 +36,19 @@ The framework integrates with `Microsoft.Extensions.AI` and `Microsoft.Extension
4936
- **Config**: Read from environment variables with `UPPER_SNAKE_CASE` naming
5037
- **Tests**: Add Arrange/Act/Assert comments; use Moq for mocking
5138

39+
## Key Design Principles
40+
41+
When developing or reviewing code, verify adherence to these key design principles:
42+
43+
- **DRY**: Avoid code duplication by moving common logic into helper methods or helper classes.
44+
- **Single Responsibility**: Each class should have one clear responsibility.
45+
- **Encapsulation**: Keep implementation details private and expose only necessary public APIs.
46+
- **Strong Typing**: Use strong typing to ensure that code is self-documenting and to catch errors at compile time.
47+
5248
## Sample Structure
5349

50+
Samples (in `./samples/` folder) should follow this structure:
51+
5452
1. Copyright header: `// Copyright (c) Microsoft. All rights reserved.`
5553
2. Description comment explaining what the sample demonstrates
5654
3. Using statements
@@ -60,6 +58,7 @@ The framework integrates with `Microsoft.Extensions.AI` and `Microsoft.Extension
6058
Configuration via environment variables (never hardcode secrets). Keep samples simple and focused.
6159

6260
When adding a new sample:
61+
6362
- Create a standalone project in `samples/` with matching directory and project names
6463
- Include a README.md explaining what the sample does and how to run it
6564
- Add the project to the solution file

0 commit comments

Comments
 (0)