You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fastmcp supports sample, but when I use adk, it says ValueError: Client does not support sampling
This is an example of how to use sampleing in fastmcp.
from fastmcp import FastMCP, Context
mcp = FastMCP("SamplingDemo")
@mcp.tool
async def analyze_sentiment(text: str, ctx: Context) -> dict:
"""Analyze the sentiment of text using the client's LLM."""
prompt = f"""Analyze the sentiment of the following text as positive, negative, or neutral.
Just output a single word - 'positive', 'negative', or 'neutral'.
Text to analyze: {text}"""
# Request LLM analysis
response = await ctx.sample(prompt)
# Process the LLM's response
sentiment = response.text.strip().lower()
# Map to standard sentiment values
if "positive" in sentiment:
sentiment = "positive"
elif "negative" in sentiment:
sentiment = "negative"
else:
sentiment = "neutral"
return {"text": text, "sentiment": sentiment}
[Workaround]: Use Server-Controlled Mode (using the Server's LLM)
# Set up server's private LLM handlerllm_handler=OpenAISamplingHandler(
default_model="gpt-4o", # Specify the gpt-4o modelclient=OpenAI(
api_key=API_KEY,
),
)
# Create the FastMCP Server instancemcp=FastMCP(
name="SamplingDemo",
# This tells the server to use its own LLMsampling_handler=llm_handler,
# This forces the server to *always* use its handler# and never ask the client (your ADK agent)sampling_handler_behavior="always"
)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
fastmcp supports sample, but when I use adk, it says ValueError: Client does not support sampling
This is an example of how to use sampleing in fastmcp.
from fastmcp import FastMCP, Context
mcp = FastMCP("SamplingDemo")
@mcp.tool
async def analyze_sentiment(text: str, ctx: Context) -> dict:
"""Analyze the sentiment of text using the client's LLM."""
prompt = f"""Analyze the sentiment of the following text as positive, negative, or neutral.
Just output a single word - 'positive', 'negative', or 'neutral'.
All reactions