Description
dotnet packages has not implemented some features of Python packages.
Because of the differences, I cannot quickly port Python code to C#.
Code Sample
session = agent.create_session()
print(session.session_id)
//c#
var currentSession = await agent.CreateSessionAsync(); // not found currentSession.SessionId???
FunctionInvocationContext
@tool(approval_mode="never_require",
description='read file')
def read_file(
ctx: FunctionInvocationContext,
file_path: str,
encoding: Optional[str] = None,
create_if_missing: bool = False
) -> Tuple[str, bool]:
print(ctx.session.session_id)
//c#
[Description("write file")]
public static (bool Success, string Message) WriteFile(
[Description("文件路径")] string file_path,
[Description("内容")] string content,
[Description("编码")] string? encoding = null,
[Description("允许覆盖")] bool overwrite = true,
FunctionInvocationContext? context = null)
{
//not found context.Session???
}
python:
`class SandboxMiddleware(AgentMiddleware):`
C# does not implement class-based middleware writing.
async with Agent(
client=client,
name="TaskMaster",
instructions="""你是专业助手**:
""",
tools=[read_file, write_file, list_directory, create_directory],
middleware=[
SandboxMiddleware(base_sandbox_dir=BASE_SANDBOX_DIR)
],
context_providers=[skills_provider],
default_options={"think": True}
) as agent:
var agent = ollamaClient.AsAIAgent(new ChatClientAgentOptions()
{
Name = "TaskMaster",
ChatOptions = new()
{
Instructions = """
你是专业助手
""",
Tools = tools,
Reasoning = new() { Effort = ReasoningEffort.High }
}
}
);
//not found agent.MiddleWare ???
Language/SDK
.NET
Description
dotnet packages has not implemented some features of Python packages.
Because of the differences, I cannot quickly port Python code to C#.
Code Sample
Language/SDK
.NET