we are using python as sdk for creating agent, is ...
# ask-ai
e
we are using python as sdk for creating agent, is there way to define instructions for the tool?
t
Thanks for reaching out, Aman. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking whether you can define instructions for a tool when building an agent with the Python SDK — yes. Define a tool by decorating a method with
@function_tool()
and put the tool's instructions in that method's docstring. The docstring should describe the tool's purpose, when to use it, details for each argument, constraints/valid values, and the expected return format. The LLM uses that docstring to decide when and how to call the tool. Example:
Copy code
from livekit.agents import Agent, function_tool
from livekit.agents.context import RunContext

class MyAgent(Agent):
    def __init__(self):
        super().__init__(instructions="You are a helpful assistant.")

    @function_tool()
    async def get_weather(self, context: RunContext, location: str) -> dict[str, Any]:
        """
        Look up weather for a location.

        Args:
            location: city and country (e.g., "New York, US"). Must be non-empty.
        Returns:
            Dict with keys "weather" and "temperature_f".
        """
        # implementation...
        return {"weather": "sunny", "temperature_f": 70}
If you want, tell me what tool you’re building and I can help write a clear docstring (instructions) that will guide the agent. Sources: Tool definition and use | LiveKit docs