Skip to content

Instantly share code, notes, and snippets.

@Cali0707
Created June 26, 2025 19:38
Show Gist options
  • Save Cali0707/203c3a0b918ec7a2c4a5b45d6e1c7d9b to your computer and use it in GitHub Desktop.
Save Cali0707/203c3a0b918ec7a2c4a5b45d6e1c7d9b to your computer and use it in GitHub Desktop.
from llama_stack_client import Agent, AgentEventLogger, RAGDocument, LlamaStackClient
from llama_stack.apis.common.content_types import URL
client = LlamaStackClient(base_url="http://localhost:8321")
models = client.models.list()
# Select the first LLM and first embedding models
model_id = next(m for m in models if m.model_type == "llm").identifier
embedding_model_id = (
em := next(m for m in models if m.model_type == "embedding")
).identifier
embedding_dimension = em.metadata["embedding_dimension"]
client.toolgroups.register(
toolgroup_id="mcp::test",
provider_id="model-context-protocol",
mcp_endpoint=URL(uri="http://localhost:8080/sse")
)
agent = Agent(
client,
model=model_id,
instructions="You are a helpful assistant",
tools=[
"mcp::test",
],
)
prompt = input("prompt>")
response = agent.create_turn(
messages=[{"role": "user", "content": prompt}],
session_id=agent.create_session("mcp-demo"),
stream=True,
)
for log in AgentEventLogger().log(response):
log.print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment