showcase/shell-docs/src/content/docs/integrations/adk/generative-ui/tool-rendering.mdx
<IframeSwitcher id="backend-tools-example" exampleUrl="https://feature-viewer.copilotkit.ai/adk-middleware/feature/backend_tool_rendering?sidebar=false&chatDefaultOpen=false" codeUrl="https://feature-viewer.copilotkit.ai/adk-middleware/feature/backend_tool_rendering?view=code&sidebar=false&codeLayout=tabs" exampleLabel="Demo" codeLabel="Code" height="700px" />
Tools are a way for the LLM to call predefined, typically, deterministic functions. CopilotKit allows you to render these tools in the UI as a custom component, which we call Generative UI.
Rendering tools in the UI is useful when you want to provide the user with feedback about what your agent is doing, specifically when your agent is calling tools. CopilotKit allows you to fully customize how these tools are rendered in the chat.
<Tabs groupId="language_adk_agent" items={['Python']} default="Python" persist> <Tab value="Python"> ```python title="agent.py" from fastapi import FastAPI from ag_ui_adk import ADKAgent, add_adk_fastapi_endpoint from google.adk.agents import LlmAgent
def get_weather(location: str = "the entire world") -> str:
"""Retrieves the current weather report for a specified location.
Args:
location (str): The name of the location to get the weather for.
Returns:
str: The weather report for the specified location.
"""
return f"The weather in {location} is sunny."
agent = LlmAgent(
model="gemini-2.5-flash",
name="my_agent",
instruction="You are a helpful weather assistant.",
tools=[get_weather],
)
adk_agent = ADKAgent(
adk_agent=agent,
app_name="weather_demo",
user_id="demo_user"
)
app = FastAPI()
add_adk_fastapi_endpoint(app, adk_agent, path="/")
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
```
</Tab>
// ...
const YourMainContent = () => {
// ...
// [!code highlight:12]
useRenderTool({
name: "get_weather",
render: ({ status, args }) => {
return (
<p className="text-gray-500 mt-2">
{status !== "complete" && "Calling weather API..."}
{status === "complete" &&
`Called the weather API for ${args.location}.`}
</p>
);
},
});
// ...
};
Try asking the agent to get the weather for a location. You should see the custom UI component that we added render the tool call and display the arguments that were passed to the tool.
<video src="https://cdn.copilotkit.ai/docs/copilotkit/images/coagents/tool-based-gen-ui.mp4" className="rounded-lg shadow-xl" loop playsInline controls autoPlay muted /> </Step> </Steps>