Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Net Agents - No ability to maniplate history for KernelFunction based strategies #8914

Closed
crickman opened this issue Sep 19, 2024 · 1 comment · Fixed by #8913
Closed

.Net Agents - No ability to maniplate history for KernelFunction based strategies #8914

crickman opened this issue Sep 19, 2024 · 1 comment · Fixed by #8913
Assignees
Labels
agents enhancement experimental Associated with an experimental feature .NET Issue or Pull requests regarding .NET code

Comments

@crickman
Copy link
Contributor

Customer Reported:

Always including the entire history can waste tokens, and unnecessarily increase operational cost.

In addition, the history may eventually exceed the token limit.

@crickman crickman added .NET Issue or Pull requests regarding .NET code agents enhancement experimental Associated with an experimental feature labels Sep 19, 2024
@crickman crickman self-assigned this Sep 19, 2024
@crickman crickman added triage and removed triage labels Sep 19, 2024
@dotnetprofessional
Copy link

This is a pain point for me right now. Need to control what history is part of the executed prompt to reduce ambiguity (ie LLM has too much context, so will get confused), save tokens. Looking forward to this being resolved.

github-merge-queue bot pushed a commit that referenced this issue Sep 20, 2024
…hat` (#8913)

### Motivation and Context
<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

Refine handling of history for `KernelFunctionSelectionStrategy` and
`KernelFunctionTerminationStrategy` based on customer input.

Fixes: #8898
Fixes: #8914

```
Determine which participant takes the next turn in a conversation based on the the most recent participant.
State only the name of the participant to take the next turn.
No participant should take more than one turn in a row.
 
Choose only from these participants:
- ArtDirector
- CopyWriter
 
Always follow these rules when selecting the next participant:
- After CopyWriter, it is ArtDirector's turn.
- After ArtDirector, it is CopyWriter's turn.
 
History:
[
  {
    "Role": "user",
    "Content": "concept: maps made out of egg cartons."
  },
  {
    "Role": "Assistant",
    "Name": "CopyWriter",
    "Content": "Navigate your world, one carton at a time."
  }
  {
    "Role": "Assistant",
    "Name": "ArtDirector",
    "Content": "Approved. The copy effectively conveys the concept with a clever and concise tagline."
  }
]
```

### Description
<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

- Introduce convenience method (static) to create a `KernelFunction`
from prompt-template and specifiy "safe" parameters.
- Internally utilize `ChatMessageForPrompt` wrapper for
`ChatMessageContent` to eliminate the inclusion of extraneous metadata
in the strategy prompt.
- Update `KernelFunctionSelectionStrategy` and
`KernelFunctionTerminationStrategy` to call
`ChatMessageForPrompt.Format` to format history for strategy prompt.
- Add optional `HistoryReducer` property to
`KernelFunctionSelectionStrategy` and
`KernelFunctionTerminationStrategy` to limit how much history is
included in the strategy prompt.
- Updated sample

### Contribution Checklist
<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agents enhancement experimental Associated with an experimental feature .NET Issue or Pull requests regarding .NET code
Projects
Status: Sprint: Done
Development

Successfully merging a pull request may close this issue.

2 participants