Skip to content

Conversation

yanxi0830
Copy link
Contributor

@yanxi0830 yanxi0830 commented Nov 1, 2024

TL;DR

  • Unify Agent class into SDK
  • Utilities for interacting with server Agent API
  • Support tool calling

Example Usage

from llama_stack_client import LlamaStackClient
from llama_stack_client.lib.agents.agent import Agent
from llama_stack_client.lib.agents.event_logger import EventLogger
from llama_stack_client.types.agent_create_params import AgentConfig

client = LlamaStackClient(
        base_url=f"http://{host}:{port}",
    )

agent_config = AgentConfig(
    model="Llama3.1-8B-Instruct",
    instructions="You are a helpful assistant",
    sampling_params={
        "strategy": "greedy",
        "temperature": 1.0,
        "top_p": 0.9,
    },
    tools=[
        {
            "type": "brave_search",
            "engine": "brave",
            "api_key": os.getenv("BRAVE_SEARCH_API_KEY"),
        }
    ],
    tool_choice="auto",
    tool_prompt_format="function_tag",
    input_shields=[],
    output_shields=[],
    enable_session_persistence=False,
)

agent = Agent(client, agent_config)
session_id = agent.create_session("test-session")
print(f"Created session_id={session_id} for Agent({agent.agent_id})")

user_prompts = [
    "I am planning a trip to Switzerland, what are the top 3 places to visit?",
    "What is so special about #1?",
    "What other countries should I consider to club?",
    "What is the capital of France?",
]

for prompt in user_prompts:
    response = agent.create_turn(
        messages=[
            {
                "role": "user",
                "content": prompt,
            }
        ],
        session_id=session_id,
    )

    async for log in EventLogger().log(response):
        log.print()

Misc changes

  • add pre-commit for /lib

@yanxi0830 yanxi0830 changed the title [WIP] Agent SDK Agent SDK in llama-stack-client Nov 1, 2024
@yanxi0830 yanxi0830 marked this pull request as ready for review November 1, 2024 23:17
@yanxi0830 yanxi0830 merged commit 9fb1895 into main Nov 4, 2024
3 checks passed
@yanxi0830 yanxi0830 deleted the agent_sdk branch November 4, 2024 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants