算法艺术创作
algorithmic-art
通过代码和可调参数创作生成艺术与交互式视觉效果。
google-adk【设计与创意】Best practices for building AI agents with Google's Agent Development Kit (ADK) in Python, covering agent design, tools, sessions, memory, artifacts, evaluation, and deployment. Use when building LLM agents or multi-agent systems with ADK, defining ADK tools, wiring up sessions/state/memory, working with ADK artifacts, writing agent evals, or deployi…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
This skill covers building production-grade AI agents with Google's Agent Development Kit (ADK) for Python, including agent composition, tool design, session/state/memory management, artifacts, evaluation, and deployment.
LlmAgent (or Agent) with a clear name, model, instruction, and description. Keep the instruction focused on one job.FunctionTool. Validate all inputs before side effects.SequentialAgent, ParallelAgent, or LoopAgent for deterministic orchestration, or delegate via sub_agents for LLM-driven routing.SessionService (in-memory for dev, DatabaseSessionService or Vertex AI-managed for production) and use session.state for conversation-scoped data.MemoryService for cross-session recall when the agent needs to remember facts between separate conversations.ArtifactService when the agent generates or receives files, images, or other binary outputs.adk web, adk run, or the Runner API to exercise the agent against a Session..evalset.json test cases and run adk eval to check tool-call trajectories and response quality against regressions.LlmAgent for flexible, reasoning-driven behavior and workflow agents (SequentialAgent, ParallelAgent, LoopAgent) for deterministic orchestration that doesn't need an LLM to decide the next step.lookup_order before answering order questions"), and escalation behavior ("if you cannot resolve the issue, transfer to human_handoff_agent").gemini-2.0-flash, gemini-2.5-pro, or other supported models without code changes.output_schema (a Pydantic model) when the agent's final response must be structured data consumed by other code.{"status": "error", "message": "order_id not found"}) rather than raising unhandled exceptions that break the agent loop.google_search, code_execution) cannot be combined with other tools on the same agent; delegate to a dedicated sub-agent instead.FunctionTool for custom Python logic, AgentTool to let one agent call another agent as a tool, and built-in tools (google_search, BuiltInCodeExecutor) only when their constraints fit the use case.from google.adk.agents import Agent
from google.adk.tools import FunctionTool
from google.adk.runners import InMemoryRunner
from google.genai import types
def get_order_status(order_id: str) -> dict:
"""Look up the current status of a customer order.
Args:
order_id: The unique identifier of the order, e.g. "ord-12345".
Returns:
A dict with 'status' ('found' or 'error') and either 'state'
and 'updated_at', or an error 'message'.
"""
if not order_id or not order_id.startswith("ord-"):
return {"status": "error", "message": "invalid order_id format"}
# In production this would call a real order service.
orders = {"ord-12345": {"state": "shipped", "updated_at": "2026-08-30T10:00:00Z"}}
order = orders.get(order_id)
if order is None:
return {"status": "error", "message": f"no order found for {order_id}"}
return {"status": "found", **order}
root_agent = Agent(
name="order_support_agent",
model="gemini-2.0-flash",
description="Answers customer questions about order status.",
instruction=(
"You help customers check their order status. "
"Always call get_order_status before answering an order question. "
"If the tool returns an error, apologize and ask the customer to "
"double-check their order ID. Never invent an order status."
),
tools=[FunctionTool(func=get_order_status)],
)
async def main() -> None:
runner = InMemoryRunner(agent=root_agent, app_name="order_support")
session = await runner.session_service.create_session(
app_name="order_support", user_id="user-1"
)
message = types.Content(
role="user", parts=[types.Part(text="What's the status of ord-12345?")]
)
async for event in runner.run_async(
user_id="user-1", session_id=session.id, new_message=message
):
if event.content and event.content.parts:
for part in event.content.parts:
if part.text:
print(part.text)
if __name__ == "__main__":
import asyncio
asyncio.run(main())
session.state for current-conversation data — user preferences discovered mid-conversation, counters, intermediate results.MemoryService for cross-session recall and retrieval (facts that should persist after the session ends and be searchable in future sessions).user:, app:, temp:) to scope state lifetime consistently across the app.DatabaseSessionService or the managed Vertex AI session service instead of InMemorySessionService, which loses all state on process restart.ArtifactService (e.g., InMemoryArtifactService for dev, GcsArtifactService for production) on the Runner before relying on artifact operations like save_artifact or load_artifact.report_v2.pdf as the artifact and "generated report v2" as the state note..evalset.json test cases covering tool-call trajectories (which tools were called, in what order, with what arguments) and final response quality.adk eval <agent_module> <eval_set_file> in CI to catch prompt regressions before merging instruction changes.adk web's trace view, or Runner events) to debug agent decisions — inspect which tool was called, what arguments were passed, and what the model saw.SessionService/ArtifactService backends, different API keys, different model tiers).adk deploy cloud_run / a custom Dockerfile for Cloud Run or GKE when more control over the environment is needed.process or handle — name tools for what they actually do.output_key or output_schema when downstream code depends on a structured final response, leading to fragile string parsing.