diff --git a/README.md b/README.md index 0439d6e..b3ae224 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ A curated collection of **Awesome LLM apps built with RAG, AI Agents, Multi-agen * [๐จ AI Game Design Agent Team](advanced_ai_agents/multi_agent_apps/agent_teams/ai_game_design_agent_team/) * [๐จโโ๏ธ AI Legal Agent Team (Cloud & Local)](advanced_ai_agents/multi_agent_apps/agent_teams/ai_legal_agent_team/) * [๐ผ AI Recruitment Agent Team](advanced_ai_agents/multi_agent_apps/agent_teams/ai_recruitment_agent_team/) +* [๐ AI Real Estate Agent Team](advanced_ai_agents/multi_agent_apps/agent_teams/ai_real_estate_agent_team) * [๐จโ๐ผ AI Services Agency (CrewAI)](advanced_ai_agents/multi_agent_apps/agent_teams/ai_services_agency/) * [๐จโ๐ซ AI Teaching Agent Team](advanced_ai_agents/multi_agent_apps/agent_teams/ai_teaching_agent_team/) * [๐ป Multimodal Coding Agent Team](advanced_ai_agents/multi_agent_apps/agent_teams/multimodal_coding_agent_team/) diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/1_starter_agent/README.md b/ai_agent_framework_crash_course/google_adk_crash_course/1_starter_agent/README.md similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/1_starter_agent/README.md rename to ai_agent_framework_crash_course/google_adk_crash_course/1_starter_agent/README.md diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/1_starter_agent/creative_writing_agent/.env.example b/ai_agent_framework_crash_course/google_adk_crash_course/1_starter_agent/creative_writing_agent/.env.example similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/1_starter_agent/creative_writing_agent/.env.example rename to ai_agent_framework_crash_course/google_adk_crash_course/1_starter_agent/creative_writing_agent/.env.example diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/1_starter_agent/creative_writing_agent/__init__.py b/ai_agent_framework_crash_course/google_adk_crash_course/1_starter_agent/creative_writing_agent/__init__.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/1_starter_agent/creative_writing_agent/__init__.py rename to ai_agent_framework_crash_course/google_adk_crash_course/1_starter_agent/creative_writing_agent/__init__.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/1_starter_agent/creative_writing_agent/agent.py b/ai_agent_framework_crash_course/google_adk_crash_course/1_starter_agent/creative_writing_agent/agent.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/1_starter_agent/creative_writing_agent/agent.py rename to ai_agent_framework_crash_course/google_adk_crash_course/1_starter_agent/creative_writing_agent/agent.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/1_starter_agent/requirements.txt b/ai_agent_framework_crash_course/google_adk_crash_course/1_starter_agent/requirements.txt similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/1_starter_agent/requirements.txt rename to ai_agent_framework_crash_course/google_adk_crash_course/1_starter_agent/requirements.txt diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/2_model_agnostic_agent/2_1_openai_adk_agent/.env.example b/ai_agent_framework_crash_course/google_adk_crash_course/2_model_agnostic_agent/2_1_openai_adk_agent/.env.example similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/2_model_agnostic_agent/2_1_openai_adk_agent/.env.example rename to ai_agent_framework_crash_course/google_adk_crash_course/2_model_agnostic_agent/2_1_openai_adk_agent/.env.example diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/2_model_agnostic_agent/2_1_openai_adk_agent/__init__.py b/ai_agent_framework_crash_course/google_adk_crash_course/2_model_agnostic_agent/2_1_openai_adk_agent/__init__.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/2_model_agnostic_agent/2_1_openai_adk_agent/__init__.py rename to ai_agent_framework_crash_course/google_adk_crash_course/2_model_agnostic_agent/2_1_openai_adk_agent/__init__.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/2_model_agnostic_agent/2_1_openai_adk_agent/agent.py b/ai_agent_framework_crash_course/google_adk_crash_course/2_model_agnostic_agent/2_1_openai_adk_agent/agent.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/2_model_agnostic_agent/2_1_openai_adk_agent/agent.py rename to ai_agent_framework_crash_course/google_adk_crash_course/2_model_agnostic_agent/2_1_openai_adk_agent/agent.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/2_model_agnostic_agent/2_2_anthropic_adk_agent/.env.example b/ai_agent_framework_crash_course/google_adk_crash_course/2_model_agnostic_agent/2_2_anthropic_adk_agent/.env.example similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/2_model_agnostic_agent/2_2_anthropic_adk_agent/.env.example rename to ai_agent_framework_crash_course/google_adk_crash_course/2_model_agnostic_agent/2_2_anthropic_adk_agent/.env.example diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/2_model_agnostic_agent/2_2_anthropic_adk_agent/__init__.py b/ai_agent_framework_crash_course/google_adk_crash_course/2_model_agnostic_agent/2_2_anthropic_adk_agent/__init__.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/2_model_agnostic_agent/2_2_anthropic_adk_agent/__init__.py rename to ai_agent_framework_crash_course/google_adk_crash_course/2_model_agnostic_agent/2_2_anthropic_adk_agent/__init__.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/2_model_agnostic_agent/2_2_anthropic_adk_agent/agent.py b/ai_agent_framework_crash_course/google_adk_crash_course/2_model_agnostic_agent/2_2_anthropic_adk_agent/agent.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/2_model_agnostic_agent/2_2_anthropic_adk_agent/agent.py rename to ai_agent_framework_crash_course/google_adk_crash_course/2_model_agnostic_agent/2_2_anthropic_adk_agent/agent.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/2_model_agnostic_agent/README.md b/ai_agent_framework_crash_course/google_adk_crash_course/2_model_agnostic_agent/README.md similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/2_model_agnostic_agent/README.md rename to ai_agent_framework_crash_course/google_adk_crash_course/2_model_agnostic_agent/README.md diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/2_model_agnostic_agent/requirements.txt b/ai_agent_framework_crash_course/google_adk_crash_course/2_model_agnostic_agent/requirements.txt similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/2_model_agnostic_agent/requirements.txt rename to ai_agent_framework_crash_course/google_adk_crash_course/2_model_agnostic_agent/requirements.txt diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/3_structured_output_agent/3_1_customer_support_ticket_agent/README.md b/ai_agent_framework_crash_course/google_adk_crash_course/3_structured_output_agent/3_1_customer_support_ticket_agent/README.md similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/3_structured_output_agent/3_1_customer_support_ticket_agent/README.md rename to ai_agent_framework_crash_course/google_adk_crash_course/3_structured_output_agent/3_1_customer_support_ticket_agent/README.md diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/3_structured_output_agent/3_1_customer_support_ticket_agent/customer_support_agent/.env.example b/ai_agent_framework_crash_course/google_adk_crash_course/3_structured_output_agent/3_1_customer_support_ticket_agent/customer_support_agent/.env.example similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/3_structured_output_agent/3_1_customer_support_ticket_agent/customer_support_agent/.env.example rename to ai_agent_framework_crash_course/google_adk_crash_course/3_structured_output_agent/3_1_customer_support_ticket_agent/customer_support_agent/.env.example diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/3_structured_output_agent/3_1_customer_support_ticket_agent/customer_support_agent/__init__.py b/ai_agent_framework_crash_course/google_adk_crash_course/3_structured_output_agent/3_1_customer_support_ticket_agent/customer_support_agent/__init__.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/3_structured_output_agent/3_1_customer_support_ticket_agent/customer_support_agent/__init__.py rename to ai_agent_framework_crash_course/google_adk_crash_course/3_structured_output_agent/3_1_customer_support_ticket_agent/customer_support_agent/__init__.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/3_structured_output_agent/3_1_customer_support_ticket_agent/customer_support_agent/agent.py b/ai_agent_framework_crash_course/google_adk_crash_course/3_structured_output_agent/3_1_customer_support_ticket_agent/customer_support_agent/agent.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/3_structured_output_agent/3_1_customer_support_ticket_agent/customer_support_agent/agent.py rename to ai_agent_framework_crash_course/google_adk_crash_course/3_structured_output_agent/3_1_customer_support_ticket_agent/customer_support_agent/agent.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/3_structured_output_agent/3_1_customer_support_ticket_agent/requirements.txt b/ai_agent_framework_crash_course/google_adk_crash_course/3_structured_output_agent/3_1_customer_support_ticket_agent/requirements.txt similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/3_structured_output_agent/3_1_customer_support_ticket_agent/requirements.txt rename to ai_agent_framework_crash_course/google_adk_crash_course/3_structured_output_agent/3_1_customer_support_ticket_agent/requirements.txt diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/3_structured_output_agent/3_2_email_agent/README.md b/ai_agent_framework_crash_course/google_adk_crash_course/3_structured_output_agent/3_2_email_agent/README.md similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/3_structured_output_agent/3_2_email_agent/README.md rename to ai_agent_framework_crash_course/google_adk_crash_course/3_structured_output_agent/3_2_email_agent/README.md diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/3_structured_output_agent/3_2_email_agent/email_generator_agent/.env.example b/ai_agent_framework_crash_course/google_adk_crash_course/3_structured_output_agent/3_2_email_agent/email_generator_agent/.env.example similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/3_structured_output_agent/3_2_email_agent/email_generator_agent/.env.example rename to ai_agent_framework_crash_course/google_adk_crash_course/3_structured_output_agent/3_2_email_agent/email_generator_agent/.env.example diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/3_structured_output_agent/3_2_email_agent/email_generator_agent/__init__.py b/ai_agent_framework_crash_course/google_adk_crash_course/3_structured_output_agent/3_2_email_agent/email_generator_agent/__init__.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/3_structured_output_agent/3_2_email_agent/email_generator_agent/__init__.py rename to ai_agent_framework_crash_course/google_adk_crash_course/3_structured_output_agent/3_2_email_agent/email_generator_agent/__init__.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/3_structured_output_agent/3_2_email_agent/email_generator_agent/agent.py b/ai_agent_framework_crash_course/google_adk_crash_course/3_structured_output_agent/3_2_email_agent/email_generator_agent/agent.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/3_structured_output_agent/3_2_email_agent/email_generator_agent/agent.py rename to ai_agent_framework_crash_course/google_adk_crash_course/3_structured_output_agent/3_2_email_agent/email_generator_agent/agent.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/3_structured_output_agent/3_2_email_agent/requirements.txt b/ai_agent_framework_crash_course/google_adk_crash_course/3_structured_output_agent/3_2_email_agent/requirements.txt similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/3_structured_output_agent/3_2_email_agent/requirements.txt rename to ai_agent_framework_crash_course/google_adk_crash_course/3_structured_output_agent/3_2_email_agent/requirements.txt diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/3_structured_output_agent/README.md b/ai_agent_framework_crash_course/google_adk_crash_course/3_structured_output_agent/README.md similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/3_structured_output_agent/README.md rename to ai_agent_framework_crash_course/google_adk_crash_course/3_structured_output_agent/README.md diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_1_builtin_tools/.env.example b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_1_builtin_tools/.env.example similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_1_builtin_tools/.env.example rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_1_builtin_tools/.env.example diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_1_builtin_tools/README.md b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_1_builtin_tools/README.md similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_1_builtin_tools/README.md rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_1_builtin_tools/README.md diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_1_builtin_tools/code_exec_agent/__init__.py b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_1_builtin_tools/code_exec_agent/__init__.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_1_builtin_tools/code_exec_agent/__init__.py rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_1_builtin_tools/code_exec_agent/__init__.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_1_builtin_tools/code_exec_agent/agent.py b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_1_builtin_tools/code_exec_agent/agent.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_1_builtin_tools/code_exec_agent/agent.py rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_1_builtin_tools/code_exec_agent/agent.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_1_builtin_tools/requirements.txt b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_1_builtin_tools/requirements.txt similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_1_builtin_tools/requirements.txt rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_1_builtin_tools/requirements.txt diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_1_builtin_tools/search_agent/__init__.py b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_1_builtin_tools/search_agent/__init__.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_1_builtin_tools/search_agent/__init__.py rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_1_builtin_tools/search_agent/__init__.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_1_builtin_tools/search_agent/agent.py b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_1_builtin_tools/search_agent/agent.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_1_builtin_tools/search_agent/agent.py rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_1_builtin_tools/search_agent/agent.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_2_function_tools/README.md b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_2_function_tools/README.md similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_2_function_tools/README.md rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_2_function_tools/README.md diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_2_function_tools/calculator_agent/__init__.py b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_2_function_tools/calculator_agent/__init__.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_2_function_tools/calculator_agent/__init__.py rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_2_function_tools/calculator_agent/__init__.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_2_function_tools/calculator_agent/agent.py b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_2_function_tools/calculator_agent/agent.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_2_function_tools/calculator_agent/agent.py rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_2_function_tools/calculator_agent/agent.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_2_function_tools/calculator_agent/tools.py b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_2_function_tools/calculator_agent/tools.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_2_function_tools/calculator_agent/tools.py rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_2_function_tools/calculator_agent/tools.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_2_function_tools/requirements.txt b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_2_function_tools/requirements.txt similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_2_function_tools/requirements.txt rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_2_function_tools/requirements.txt diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_2_function_tools/utility_agent/__init__.py b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_2_function_tools/utility_agent/__init__.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_2_function_tools/utility_agent/__init__.py rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_2_function_tools/utility_agent/__init__.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_2_function_tools/utility_agent/agent.py b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_2_function_tools/utility_agent/agent.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_2_function_tools/utility_agent/agent.py rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_2_function_tools/utility_agent/agent.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_2_function_tools/utility_agent/tools.py b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_2_function_tools/utility_agent/tools.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_2_function_tools/utility_agent/tools.py rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_2_function_tools/utility_agent/tools.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_3_thirdparty_tools/.env.example b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_3_thirdparty_tools/.env.example similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_3_thirdparty_tools/.env.example rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_3_thirdparty_tools/.env.example diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_3_thirdparty_tools/README.md b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_3_thirdparty_tools/README.md similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_3_thirdparty_tools/README.md rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_3_thirdparty_tools/README.md diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_3_thirdparty_tools/crewai_agent/__init__.py b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_3_thirdparty_tools/crewai_agent/__init__.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_3_thirdparty_tools/crewai_agent/__init__.py rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_3_thirdparty_tools/crewai_agent/__init__.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_3_thirdparty_tools/crewai_agent/agent.py b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_3_thirdparty_tools/crewai_agent/agent.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_3_thirdparty_tools/crewai_agent/agent.py rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_3_thirdparty_tools/crewai_agent/agent.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_3_thirdparty_tools/langchain_agent/__init__.py b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_3_thirdparty_tools/langchain_agent/__init__.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_3_thirdparty_tools/langchain_agent/__init__.py rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_3_thirdparty_tools/langchain_agent/__init__.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_3_thirdparty_tools/langchain_agent/agent.py b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_3_thirdparty_tools/langchain_agent/agent.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_3_thirdparty_tools/langchain_agent/agent.py rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_3_thirdparty_tools/langchain_agent/agent.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_3_thirdparty_tools/requirements.txt b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_3_thirdparty_tools/requirements.txt similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_3_thirdparty_tools/requirements.txt rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_3_thirdparty_tools/requirements.txt diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_4_mcp_tools/.env.example b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_4_mcp_tools/.env.example similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_4_mcp_tools/.env.example rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_4_mcp_tools/.env.example diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_4_mcp_tools/README.md b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_4_mcp_tools/README.md similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_4_mcp_tools/README.md rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_4_mcp_tools/README.md diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_4_mcp_tools/filesystem_agent/README.md b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_4_mcp_tools/filesystem_agent/README.md similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_4_mcp_tools/filesystem_agent/README.md rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_4_mcp_tools/filesystem_agent/README.md diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_4_mcp_tools/filesystem_agent/__init__.py b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_4_mcp_tools/filesystem_agent/__init__.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_4_mcp_tools/filesystem_agent/__init__.py rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_4_mcp_tools/filesystem_agent/__init__.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_4_mcp_tools/filesystem_agent/agent.py b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_4_mcp_tools/filesystem_agent/agent.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_4_mcp_tools/filesystem_agent/agent.py rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_4_mcp_tools/filesystem_agent/agent.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_4_mcp_tools/firecrawl_agent/README.md b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_4_mcp_tools/firecrawl_agent/README.md similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_4_mcp_tools/firecrawl_agent/README.md rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_4_mcp_tools/firecrawl_agent/README.md diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_4_mcp_tools/firecrawl_agent/__init__.py b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_4_mcp_tools/firecrawl_agent/__init__.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_4_mcp_tools/firecrawl_agent/__init__.py rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_4_mcp_tools/firecrawl_agent/__init__.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_4_mcp_tools/firecrawl_agent/agent.py b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_4_mcp_tools/firecrawl_agent/agent.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_4_mcp_tools/firecrawl_agent/agent.py rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_4_mcp_tools/firecrawl_agent/agent.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_4_mcp_tools/requirements.txt b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_4_mcp_tools/requirements.txt similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/4_4_mcp_tools/requirements.txt rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/4_4_mcp_tools/requirements.txt diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/README.md b/ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/README.md similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/4_tool_using_agent/README.md rename to ai_agent_framework_crash_course/google_adk_crash_course/4_tool_using_agent/README.md diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/5_memory_agent/5_1_in_memory_conversation_agent/.env.example b/ai_agent_framework_crash_course/google_adk_crash_course/5_memory_agent/5_1_in_memory_conversation_agent/.env.example similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/5_memory_agent/5_1_in_memory_conversation_agent/.env.example rename to ai_agent_framework_crash_course/google_adk_crash_course/5_memory_agent/5_1_in_memory_conversation_agent/.env.example diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/5_memory_agent/5_1_in_memory_conversation_agent/README.md b/ai_agent_framework_crash_course/google_adk_crash_course/5_memory_agent/5_1_in_memory_conversation_agent/README.md similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/5_memory_agent/5_1_in_memory_conversation_agent/README.md rename to ai_agent_framework_crash_course/google_adk_crash_course/5_memory_agent/5_1_in_memory_conversation_agent/README.md diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/5_memory_agent/5_1_in_memory_conversation_agent/agent.py b/ai_agent_framework_crash_course/google_adk_crash_course/5_memory_agent/5_1_in_memory_conversation_agent/agent.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/5_memory_agent/5_1_in_memory_conversation_agent/agent.py rename to ai_agent_framework_crash_course/google_adk_crash_course/5_memory_agent/5_1_in_memory_conversation_agent/agent.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/5_memory_agent/5_1_in_memory_conversation_agent/app.py b/ai_agent_framework_crash_course/google_adk_crash_course/5_memory_agent/5_1_in_memory_conversation_agent/app.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/5_memory_agent/5_1_in_memory_conversation_agent/app.py rename to ai_agent_framework_crash_course/google_adk_crash_course/5_memory_agent/5_1_in_memory_conversation_agent/app.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/5_memory_agent/5_1_in_memory_conversation_agent/requirements.txt b/ai_agent_framework_crash_course/google_adk_crash_course/5_memory_agent/5_1_in_memory_conversation_agent/requirements.txt similarity index 72% rename from ai_agent_framework_crash_course/google_adk_tutorials/5_memory_agent/5_1_in_memory_conversation_agent/requirements.txt rename to ai_agent_framework_crash_course/google_adk_crash_course/5_memory_agent/5_1_in_memory_conversation_agent/requirements.txt index 0a14da2..2debdf7 100644 --- a/ai_agent_framework_crash_course/google_adk_tutorials/5_memory_agent/5_1_in_memory_conversation_agent/requirements.txt +++ b/ai_agent_framework_crash_course/google_adk_crash_course/5_memory_agent/5_1_in_memory_conversation_agent/requirements.txt @@ -1,4 +1,4 @@ -google-adk==1.9.0 +google-adk>=1.9.0 streamlit>=1.47.1 python-dotenv>=1.1.1 asyncio \ No newline at end of file diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/5_memory_agent/5_2_persistent_conversation_agent/.env.example b/ai_agent_framework_crash_course/google_adk_crash_course/5_memory_agent/5_2_persistent_conversation_agent/.env.example similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/5_memory_agent/5_2_persistent_conversation_agent/.env.example rename to ai_agent_framework_crash_course/google_adk_crash_course/5_memory_agent/5_2_persistent_conversation_agent/.env.example diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/5_memory_agent/5_2_persistent_conversation_agent/README.md b/ai_agent_framework_crash_course/google_adk_crash_course/5_memory_agent/5_2_persistent_conversation_agent/README.md similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/5_memory_agent/5_2_persistent_conversation_agent/README.md rename to ai_agent_framework_crash_course/google_adk_crash_course/5_memory_agent/5_2_persistent_conversation_agent/README.md diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/5_memory_agent/5_2_persistent_conversation_agent/agent.py b/ai_agent_framework_crash_course/google_adk_crash_course/5_memory_agent/5_2_persistent_conversation_agent/agent.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/5_memory_agent/5_2_persistent_conversation_agent/agent.py rename to ai_agent_framework_crash_course/google_adk_crash_course/5_memory_agent/5_2_persistent_conversation_agent/agent.py diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/5_memory_agent/5_2_persistent_conversation_agent/app.py b/ai_agent_framework_crash_course/google_adk_crash_course/5_memory_agent/5_2_persistent_conversation_agent/app.py similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/5_memory_agent/5_2_persistent_conversation_agent/app.py rename to ai_agent_framework_crash_course/google_adk_crash_course/5_memory_agent/5_2_persistent_conversation_agent/app.py diff --git a/ai_agent_framework_crash_course/google_adk_crash_course/5_memory_agent/5_2_persistent_conversation_agent/requirements.txt b/ai_agent_framework_crash_course/google_adk_crash_course/5_memory_agent/5_2_persistent_conversation_agent/requirements.txt new file mode 100644 index 0000000..b4f2fb1 --- /dev/null +++ b/ai_agent_framework_crash_course/google_adk_crash_course/5_memory_agent/5_2_persistent_conversation_agent/requirements.txt @@ -0,0 +1,5 @@ +google-adk>=1.9.0 +streamlit>=1.47.1 +python-dotenv>=1.1.1 +sqlalchemy>=2.0.0 +asyncio \ No newline at end of file diff --git a/ai_agent_framework_crash_course/google_adk_tutorials/5_memory_agent/README.md b/ai_agent_framework_crash_course/google_adk_crash_course/5_memory_agent/README.md similarity index 100% rename from ai_agent_framework_crash_course/google_adk_tutorials/5_memory_agent/README.md rename to ai_agent_framework_crash_course/google_adk_crash_course/5_memory_agent/README.md diff --git a/ai_agent_framework_crash_course/google_adk_crash_course/6_callbacks/6_1_agent_lifecycle_callbacks/.env.example b/ai_agent_framework_crash_course/google_adk_crash_course/6_callbacks/6_1_agent_lifecycle_callbacks/.env.example new file mode 100644 index 0000000..f5cfcfb --- /dev/null +++ b/ai_agent_framework_crash_course/google_adk_crash_course/6_callbacks/6_1_agent_lifecycle_callbacks/.env.example @@ -0,0 +1,3 @@ +# If using Gemini via Google AI Studio +GOOGLE_GENAI_USE_VERTEXAI=False +GOOGLE_API_KEY="your-api-key" \ No newline at end of file diff --git a/ai_agent_framework_crash_course/google_adk_crash_course/6_callbacks/6_1_agent_lifecycle_callbacks/README.md b/ai_agent_framework_crash_course/google_adk_crash_course/6_callbacks/6_1_agent_lifecycle_callbacks/README.md new file mode 100644 index 0000000..d8cda71 --- /dev/null +++ b/ai_agent_framework_crash_course/google_adk_crash_course/6_callbacks/6_1_agent_lifecycle_callbacks/README.md @@ -0,0 +1,233 @@ +# 6.1 Agent Lifecycle Callbacks + +This tutorial demonstrates how to use `before_agent_callback` and `after_agent_callback` to monitor agent execution lifecycle. + +## ๐ฏ Learning Objectives + +- Understand agent lifecycle callbacks +- Learn how to monitor agent execution timing +- See how to share state between callbacks +- Practice implementing performance monitoring + +## ๐ Project Structure + +``` +6_1_agent_lifecycle_callbacks/ +โโโ agent.py # Agent with lifecycle callbacks +โโโ app.py # Streamlit web interface +โโโ requirements.txt # Python dependencies +โโโ README.md # This file +``` + +## ๐ง Setup + +1. **Install dependencies:** + ```bash + pip install -r requirements.txt + ``` + +2. **Set up API key:** + ```bash + # Create .env file + echo "GOOGLE_API_KEY=your_api_key_here" > .env + ``` + +## ๐ Running the Demo + +### Command Line Demo +```bash +python agent.py +``` + +### Web Interface +```bash +streamlit run app.py +``` + +## ๐ง Core Concept: Agent Lifecycle Monitoring + +Agent lifecycle callbacks allow you to monitor the beginning and end of agent execution, providing visibility into when agents start and complete their tasks. + +### **Agent Lifecycle Flow** + +``` +โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ +โ User Input โโโโโถโ Agent Start โโโโโถโ Agent End โ +โ โ โ Callback โ โ Callback โ +โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ + โ โ + โผ โผ + โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ + โ Agent Logic โ โ Performance โ + โ Execution โ โ Metrics โ + โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ +``` + +### **Callback Execution Timeline** + +``` +Timeline: โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโถ + +User Message + โ + โผ +โโโโโโโโโโโโโโโโโโโ +โ before_agent โ โ Records start time, agent info +โ _callback โ +โโโโโโโโโโโโโโโโโโโ + โ + โผ +โโโโโโโโโโโโโโโโโโโ +โ Agent Logic โ โ Core agent processing +โ Execution โ +โโโโโโโโโโโโโโโโโโโ + โ + โผ +โโโโโโโโโโโโโโโโโโโ +โ after_agent โ โ Calculates duration, logs completion +โ _callback โ +โโโโโโโโโโโโโโโโโโโ + โ + โผ +Response to User +``` + +## ๐ Code Walkthrough + +### **1. Callback Functions** + +The callbacks work in pairs to monitor the complete agent lifecycle: + +**Before Callback (`before_agent_callback`):** +- Records execution start timestamp +- Stores start time in session state for after callback +- Logs agent execution start (agent name, time) +- Returns `None` to allow normal execution + +**After Callback (`after_agent_callback`):** +- Retrieves start time from session state +- Calculates total execution duration +- Logs completion with performance metrics +- Returns `None` to use original result + +### **2. State Management Between Callbacks** + +``` +Session State Flow: +โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ +โ before_callback โโโโโถโ Session State โโโโโถโ after_callback โ +โ stores: โ โ โ โ retrieves: โ +โ - start_time โ โ - request_start โ โ - start_time โ +โ โ โ _time โ โ โ +โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ +``` + +### **3. Agent Setup** + +The agent is configured with both lifecycle callbacks: +- `before_agent_callback`: Monitors agent execution start +- `after_agent_callback`: Monitors agent execution completion +- Uses `InMemoryRunner` for proper callback triggering + +## ๐งช Testing Examples + +### **Example Output Format** + +``` +๐ Agent LifecycleDemoAgent started at 19:15:30 +โฐ Start time: 2024-01-15 19:15:30 + +โ Agent LifecycleDemoAgent completed +โฑ๏ธ Duration: 1.23s +โฐ End time: 2024-01-15 19:15:31 +๐ Performance: 1.23s | LifecycleDemoAgent + +``` + +### **What Each Metric Tells You** + +- **๐ Start time**: When the agent began processing +- **โ Completion time**: When the agent finished processing +- **โฑ๏ธ Duration**: Total execution time in seconds +- **๐ Performance**: Formatted performance summary + +## ๐ Key Concepts + +### **Agent Lifecycle Monitoring** +- **Execution Start**: Track when agents begin processing +- **Execution End**: Track when agents complete their tasks +- **Performance Timing**: Calculate total execution duration +- **State Sharing**: Pass timing data between callbacks + +### **CallbackContext** +- **agent_name**: Name of the agent being executed +- **invocation_id**: Unique identifier for this execution +- **state**: Session state that persists between callbacks + +### **State Management** +- Use `callback_context.state.to_dict()` to get current state +- Use `callback_context.state.update()` to modify state +- State is shared between before and after callbacks + +## ๐ฏ Use Cases + +- **Performance Monitoring**: Track execution times +- **Logging**: Record agent activities +- **Analytics**: Collect usage statistics +- **Debugging**: Monitor agent behavior +- **Custom Logic**: Add pre/post processing + +## ๐จ Common Mistakes + +1. **Forgetting to await session creation:** + ```python + # โ Wrong + session_service.create_session(...) + + # โ Correct + await session_service.create_session(...) + ``` + +2. **Using wrong callback signature:** + ```python + # โ Wrong + def after_agent_callback(context, result): + + # โ Correct + def after_agent_callback(callback_context: CallbackContext): + ``` + +3. **Not using InMemoryRunner:** + ```python + # โ Wrong - callbacks won't trigger + agent.run(message) + + # โ Correct + runner.run_async(...) + ``` + +## โ ๏ธ Critical Implementation Note + +**Event Loop Completion**: The `after_agent_callback` will not trigger if you break the event loop immediately upon receiving `is_final_response()`. + +**Correct Pattern**: Allow the event loop to complete naturally: +```python +# โ Wrong - breaks loop early, after_agent_callback won't run +if event.is_final_response() and event.content: + response_text = event.content.parts[0].text.strip() + break # This prevents after_agent_callback from running + +# โ Correct - let loop complete naturally +if event.is_final_response() and event.content: + response_text = event.content.parts[0].text.strip() + # Don't break - let the loop complete to ensure callbacks run +``` + +This is a known ADK behavior where breaking the loop early prevents cleanup callbacks from executing. + +## ๐ Next Steps + +- Try Tutorial 6.2: LLM Interaction Callbacks +- Experiment with state management between callbacks +- Add custom logging or analytics +- Implement performance alerts for slow responses \ No newline at end of file diff --git a/ai_agent_framework_crash_course/google_adk_crash_course/6_callbacks/6_1_agent_lifecycle_callbacks/agent.py b/ai_agent_framework_crash_course/google_adk_crash_course/6_callbacks/6_1_agent_lifecycle_callbacks/agent.py new file mode 100644 index 0000000..fee9d2a --- /dev/null +++ b/ai_agent_framework_crash_course/google_adk_crash_course/6_callbacks/6_1_agent_lifecycle_callbacks/agent.py @@ -0,0 +1,122 @@ +import os +import asyncio +from datetime import datetime +from typing import Optional +from google.adk.agents import LlmAgent +from google.adk.agents.callback_context import CallbackContext +from google.adk.runners import InMemoryRunner +from google.genai import types +from dotenv import load_dotenv + +# Load environment variables +load_dotenv() + + +# --- 1. Define the Callback Functions --- +def before_agent_callback(callback_context: CallbackContext) -> Optional[types.Content]: + """Callback before agent execution starts""" + agent_name = callback_context.agent_name + start_time = datetime.now() + + print(f"๐ Agent {agent_name} started at {start_time.strftime('%H:%M:%S')}") + print(f"โฐ Start time: {start_time.strftime('%Y-%m-%d %H:%M:%S')}") + print() # Add spacing + + # Store start time in state for after callback + current_state = callback_context.state.to_dict() + current_state["start_time"] = start_time.isoformat() + callback_context.state.update(current_state) + + return None + +def after_agent_callback(callback_context: CallbackContext) -> Optional[types.Content]: + """Callback after agent execution completes""" + agent_name = callback_context.agent_name + current_state = callback_context.state.to_dict() + + # Get start time from state + start_time_str = current_state.get("start_time") + if start_time_str: + start_time = datetime.fromisoformat(start_time_str) + end_time = datetime.now() + duration = end_time - start_time + duration_seconds = duration.total_seconds() + + print(f"โ Agent {agent_name} completed") + print(f"โฑ๏ธ Duration: {duration_seconds:.2f}s") + print(f"โฐ End time: {end_time.strftime('%Y-%m-%d %H:%M:%S')}") + print(f"๐ Performance: {duration_seconds:.2f}s | {agent_name}") + print() # Add spacing + + return None + +# --- 2. Setup Agent with Callbacks --- +llm_agent_with_callbacks = LlmAgent( + name="agent_lifecycle_demo_agent", + model="gemini-2.5-flash", + instruction="You are a helpful assistant. Respond to user questions clearly and concisely.", + description="An LLM agent demonstrating lifecycle callbacks for monitoring", + before_agent_callback=before_agent_callback, + after_agent_callback=after_agent_callback +) + +# --- 3. Setup Runner and Sessions --- +runner = InMemoryRunner(agent=llm_agent_with_callbacks, app_name="agent_lifecycle_callback_demo") + +async def run_agent(message: str) -> str: + """Run the agent with the given message""" + user_id = "demo_user" + session_id = "demo_session" + + # Get the bundled session service + session_service = runner.session_service + + # Get or create session + session = await session_service.get_session( + app_name="agent_lifecycle_callback_demo", + user_id=user_id, + session_id=session_id + ) + if not session: + session = await session_service.create_session( + app_name="agent_lifecycle_callback_demo", + user_id=user_id, + session_id=session_id, + state={"conversation_history": []} + ) + + # Create user content + user_content = types.Content( + role='user', + parts=[types.Part(text=message)] + ) + + # Run agent and get response + response_text = "" + async for event in runner.run_async( + user_id=user_id, + session_id=session_id, + new_message=user_content + ): + if event.is_final_response() and event.content: + response_text = event.content.parts[0].text.strip() + # Don't break here - let the loop complete naturally to ensure after_agent_callback runs + + return response_text + +# --- 4. Execute --- +if __name__ == "__main__": + print("\n" + "="*50 + " Agent Lifecycle Callbacks Demo " + "="*50) + + # Test messages + test_messages = [ + "Hello, how are you?" + ] + + async def test_agent(): + for i, message in enumerate(test_messages, 1): + print(f"\n--- Test {i}: {message} ---") + response = await run_agent(message) + print(f"๐ค Response: {response}") + + asyncio.run(test_agent()) \ No newline at end of file diff --git a/ai_agent_framework_crash_course/google_adk_crash_course/6_callbacks/6_1_agent_lifecycle_callbacks/app.py b/ai_agent_framework_crash_course/google_adk_crash_course/6_callbacks/6_1_agent_lifecycle_callbacks/app.py new file mode 100644 index 0000000..98c2fcf --- /dev/null +++ b/ai_agent_framework_crash_course/google_adk_crash_course/6_callbacks/6_1_agent_lifecycle_callbacks/app.py @@ -0,0 +1,165 @@ +#!/usr/bin/env python3 +""" +Streamlit App for Agent Lifecycle Callbacks Demo +""" + +import streamlit as st +import asyncio +from agent import llm_agent_with_callbacks, runner +from google.genai import types + +# Page configuration +st.set_page_config( + page_title="Agent Lifecycle Callbacks Demo", + page_icon="๐", + layout="wide" +) + +# Title and description +st.title("๐ Agent Lifecycle Callbacks Demo") +st.markdown(""" +This demo shows how to use `before_agent_callback` and `after_agent_callback` to monitor agent execution. +Watch the console output to see the callback timing information. +""") + +# Sidebar +with st.sidebar: + st.header("๐ Callback Information") + st.markdown(""" + **Before Callback:** + - Records start time + - Logs agent execution start + + **After Callback:** + - Calculates execution duration + - Logs completion time + """) + + st.header("๐ง Technical Details") + st.markdown(""" + - Uses `InMemoryRunner` for session management + - Callbacks receive `CallbackContext` with agent info + - State is shared between callbacks via session + """) + +# Main chat interface +st.header("๐ฌ Chat with Agent") + +# Define the get_response function +async def get_response(prompt_text: str) -> str: + """Run agent with the given prompt""" + user_id = "demo_user" + session_id = "demo_session" + + # Get the bundled session service + session_service = runner.session_service + + # Get or create session + session = await session_service.get_session( + app_name="agent_lifecycle_callback_demo", + user_id=user_id, + session_id=session_id + ) + if not session: + session = await session_service.create_session( + app_name="agent_lifecycle_callback_demo", + user_id=user_id, + session_id=session_id + ) + + # Create user content + user_content = types.Content( + role='user', + parts=[types.Part(text=prompt_text)] + ) + + # Run agent and get response + response_text = "" + async for event in runner.run_async( + user_id=user_id, + session_id=session_id, + new_message=user_content + ): + if event.is_final_response() and event.content: + response_text = event.content.parts[0].text.strip() + # Don't break - let the loop complete to ensure callbacks run + + return response_text + +# Initialize chat history +if "messages" not in st.session_state: + st.session_state.messages = [] + +# Display chat messages +for message in st.session_state.messages: + with st.chat_message(message["role"]): + st.markdown(message["content"]) + +# Chat input +if prompt := st.chat_input("Ask me anything..."): + # Add user message to chat history + st.session_state.messages.append({"role": "user", "content": prompt}) + with st.chat_message("user"): + st.markdown(prompt) + + # Add assistant response to chat history + with st.chat_message("assistant"): + message_placeholder = st.empty() + + # Show loading message + message_placeholder.markdown("๐ค Thinking...") + + # Get response + response = asyncio.run(get_response(prompt)) + + # Update placeholder with response + message_placeholder.markdown(response) + + # Add assistant response to chat history + st.session_state.messages.append({"role": "assistant", "content": response}) + +# Quick test buttons +st.markdown("---") +st.header("โก Quick Tests") + +col1, col2, col3 = st.columns(3) + +with col1: + if st.button("๐ Greeting Test"): + with st.chat_message("user"): + st.markdown("Hello, how are you?") + with st.chat_message("assistant"): + with st.spinner("๐ค Agent is processing..."): + response = asyncio.run(get_response("Hello, how are you?")) + st.markdown(response) + +with col2: + if st.button("๐งฎ Math Test"): + with st.chat_message("user"): + st.markdown("What's 2 + 2?") + with st.chat_message("assistant"): + with st.spinner("๐ค Agent is processing..."): + response = asyncio.run(get_response("What's 2 + 2?")) + st.markdown(response) + +with col3: + if st.button("๐ Joke Test"): + with st.chat_message("user"): + st.markdown("Tell me a short joke") + with st.chat_message("assistant"): + with st.spinner("๐ค Agent is processing..."): + response = asyncio.run(get_response("Tell me a short joke")) + st.markdown(response) + +# Clear chat button +if st.button("๐๏ธ Clear Chat"): + st.session_state.messages = [] + st.rerun() + +# Footer +st.markdown("---") +st.markdown(""" +
Check the console/terminal for callback timing information
+