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

Python: Improve agent getting started samples #10667

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

TaoChenOSU
Copy link
Contributor

@TaoChenOSU TaoChenOSU commented Feb 25, 2025

Motivation and Context

We are improving developer experience by updating the agent getting started samples.

Description

Simplify the agent getting started samples by removing unnecessary code and add excessive comments to make sure we are only doing what we need to get started.

Contribution Checklist

@TaoChenOSU TaoChenOSU added python Pull requests for the Python Semantic Kernel agents labels Feb 25, 2025
@TaoChenOSU TaoChenOSU self-assigned this Feb 25, 2025
@TaoChenOSU TaoChenOSU requested a review from a team as a code owner February 25, 2025 05:21
@github-actions github-actions bot changed the title Improve agent getting started samples Python: Improve agent getting started samples Feb 25, 2025
@@ -11,9 +11,9 @@
from semantic_kernel.functions.kernel_function_decorator import kernel_function

###################################################################
# The following sample demonstrates how to create a simple, #
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as a note, I've been updating these blocks to be contained within """<text> """ which makes it much easier to manage - no worries about having to add comment symbols to the end of lines and such...

for user_input in user_inputs:
# Add the user input as a chat message
for user_input in USER_INPUTS:
# 5. Add the user input as a chat message
await agent.add_chat_message(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As part of this PR, could we update the agent's add_chat_message signature to allow one to pass in a str, and if it's a str instance, we turn it into a ChatMessageContent(AuthorRole.USER, content=message).

await client.agents.delete_thread(thread.id)
await client.agents.delete_agent(agent.id)

# Sample Output:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, I've been adding some sample output like:

"""
Sample Output:

# User: 'Hello"
...
"""

async def main() -> None:
ai_agent_settings = AzureAIAgentSettings.create()
assert ai_agent_settings.project_connection_string, "Please provide a valid Azure AI connection string." # nosec

async with (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could probably clean up this a little bit by internally creating the AzureAIAgentSettings in the get_client method. User's can still pass in values to the method that take precedence, similar to what we do elsewhere.

print(f"# {AuthorRole.USER}: '{input}'")

# 6. Add the task as a message to the group chat
await chat.add_chat_message(ChatMessageContent(role=AuthorRole.USER, content=TASK))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a spot in my assistant agent PR where I've also allowed for await chat.add_chat_message(TASK) and we create the ChatMessageContent on behalf of the caller.

await client.agents.delete_thread(thread.id)
await client.agents.delete_agent(agent.id)

# Sample Output:
# User: 'Use code to determine the values in the Fibonacci sequence that that are less then the value of 101.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this be easier to read like:

"""
Sample Output:
User: 'Use code to determine the values in the Fibonacci sequence that that are less then the value of 101.'
Agent: # Function to generate Fibonacci sequence values less than a given limit
def fibonacci_less_than(limit):
    fib_sequence = []
    a, b = 0, 1
    while a < limit:
        fib_sequence.append(a)
        a, b = b, a + b
    a, b = 0, 1
    while a < limit:
        fib_sequence.append(a)
    a, b = 0, 1
    while a < limit:
    a, b = 0, 1
    a, b = 0, 1
    while a < limit:
        fib_sequence.append(a)
        a, b = b, a + b
    return fib_sequence

Generate Fibonacci sequence values less than 101
fibonacci_values = fibonacci_less_than(101)
fibonacci_values
Agent: The values in the Fibonacci sequence that are less than 101 are:

\[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89\]
"""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agents python Pull requests for the Python Semantic Kernel
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants