anthropic 1.72.0 → 1.73.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +33 -0
- data/README.md +2 -2
- data/lib/anthropic/helpers/messages.rb +76 -43
- data/lib/anthropic/helpers/tools/runner.rb +317 -37
- data/lib/anthropic/models/anthropic_beta.rb +6 -0
- data/lib/anthropic/models/beta/agent_archive_params.rb +12 -2
- data/lib/anthropic/models/beta/agent_create_params.rb +7 -1
- data/lib/anthropic/models/beta/agent_list_params.rb +10 -1
- data/lib/anthropic/models/beta/agent_retrieve_params.rb +9 -2
- data/lib/anthropic/models/beta/agent_update_params.rb +9 -2
- data/lib/anthropic/models/beta/agents/version_list_params.rb +12 -2
- data/lib/anthropic/models/beta/beta_compaction_block.rb +74 -1
- data/lib/anthropic/models/beta/beta_compaction_block_param.rb +80 -1
- data/lib/anthropic/models/beta/beta_content_block.rb +17 -2
- data/lib/anthropic/models/beta/beta_content_block_param.rb +30 -11
- data/lib/anthropic/models/beta/beta_diagnostics.rb +2 -2
- data/lib/anthropic/models/beta/beta_dream.rb +66 -19
- data/lib/anthropic/models/beta/beta_dream_error.rb +12 -2
- data/lib/anthropic/models/beta/beta_dream_input.rb +10 -4
- data/lib/anthropic/models/beta/beta_dream_memory_store_input.rb +13 -4
- data/lib/anthropic/models/beta/beta_dream_memory_store_output.rb +10 -2
- data/lib/anthropic/models/beta/beta_dream_model_config.rb +7 -4
- data/lib/anthropic/models/beta/beta_dream_model_config_param.rb +9 -3
- data/lib/anthropic/models/beta/beta_dream_output.rb +10 -2
- data/lib/anthropic/models/beta/beta_dream_sessions_input.rb +14 -2
- data/lib/anthropic/models/beta/beta_dream_status.rb +11 -2
- data/lib/anthropic/models/beta/beta_dream_usage.rb +22 -9
- data/lib/anthropic/models/beta/beta_dreaming_error.rb +4 -2
- data/lib/anthropic/models/beta/beta_managed_agents_model.rb +5 -0
- data/lib/anthropic/models/beta/beta_mcp_tool.rb +34 -0
- data/lib/anthropic/models/beta/beta_mcp_tool_listing_block.rb +35 -0
- data/lib/anthropic/models/beta/beta_mcp_tool_listing_block_param.rb +43 -0
- data/lib/anthropic/models/beta/beta_mcp_tool_param.rb +39 -0
- data/lib/anthropic/models/beta/beta_mcp_toolset.rb +19 -1
- data/lib/anthropic/models/beta/beta_message.rb +5 -5
- data/lib/anthropic/models/beta/beta_message_param.rb +3 -3
- data/lib/anthropic/models/beta/beta_output_behavior.rb +12 -3
- data/lib/anthropic/models/beta/beta_output_behavior_create_new.rb +5 -3
- data/lib/anthropic/models/beta/beta_output_behavior_update_existing.rb +13 -4
- data/lib/anthropic/models/beta/beta_raw_content_block_start_event.rb +19 -4
- data/lib/anthropic/models/beta/beta_raw_message_stream_event.rb +1 -1
- data/lib/anthropic/models/beta/beta_request_tool_addition_block.rb +26 -10
- data/lib/anthropic/models/beta/beta_request_tool_removal_block.rb +7 -5
- data/lib/anthropic/models/beta/beta_response_tool.rb +132 -0
- data/lib/anthropic/models/beta/beta_response_tool_addition_block.rb +112 -0
- data/lib/anthropic/models/beta/beta_response_tool_change_mcp_tool_reference.rb +35 -0
- data/lib/anthropic/models/beta/beta_response_tool_change_mcp_toolset_reference.rb +28 -0
- data/lib/anthropic/models/beta/beta_response_tool_change_tool_reference.rb +30 -0
- data/lib/anthropic/models/beta/beta_response_tool_input_schema.rb +38 -0
- data/lib/anthropic/models/beta/beta_response_tool_removal_block.rb +96 -0
- data/lib/anthropic/models/beta/beta_response_tool_union.rb +92 -0
- data/lib/anthropic/models/beta/beta_target_store_held_error.rb +13 -10
- data/lib/anthropic/models/beta/beta_tool_change_tool_definition.rb +29 -0
- data/lib/anthropic/models/beta/beta_tool_change_tool_definition_param.rb +29 -0
- data/lib/anthropic/models/beta/beta_tool_change_tool_reference.rb +3 -2
- data/lib/anthropic/models/beta/beta_user_profile.rb +11 -0
- data/lib/anthropic/models/beta/beta_user_profile_enrollment_url.rb +3 -0
- data/lib/anthropic/models/beta/beta_user_profile_external_user_details.rb +5 -0
- data/lib/anthropic/models/beta/beta_user_profile_external_user_details_params.rb +5 -0
- data/lib/anthropic/models/beta/beta_user_profile_trust_grant.rb +3 -0
- data/lib/anthropic/models/beta/deployment_archive_params.rb +12 -2
- data/lib/anthropic/models/beta/deployment_create_params.rb +7 -1
- data/lib/anthropic/models/beta/deployment_list_params.rb +7 -1
- data/lib/anthropic/models/beta/deployment_pause_params.rb +12 -2
- data/lib/anthropic/models/beta/deployment_retrieve_params.rb +12 -2
- data/lib/anthropic/models/beta/deployment_run_list_params.rb +7 -1
- data/lib/anthropic/models/beta/deployment_run_params.rb +12 -2
- data/lib/anthropic/models/beta/deployment_run_retrieve_params.rb +12 -2
- data/lib/anthropic/models/beta/deployment_unpause_params.rb +12 -2
- data/lib/anthropic/models/beta/deployment_update_params.rb +9 -2
- data/lib/anthropic/models/beta/dream_archive_params.rb +12 -2
- data/lib/anthropic/models/beta/dream_cancel_params.rb +12 -2
- data/lib/anthropic/models/beta/dream_create_params.rb +41 -6
- data/lib/anthropic/models/beta/dream_list_params.rb +25 -16
- data/lib/anthropic/models/beta/dream_retrieve_params.rb +12 -2
- data/lib/anthropic/models/beta/environment_archive_params.rb +10 -1
- data/lib/anthropic/models/beta/environment_create_params.rb +7 -1
- data/lib/anthropic/models/beta/environment_delete_params.rb +10 -1
- data/lib/anthropic/models/beta/environment_list_params.rb +7 -1
- data/lib/anthropic/models/beta/environment_retrieve_params.rb +10 -1
- data/lib/anthropic/models/beta/environment_update_params.rb +7 -1
- data/lib/anthropic/models/beta/environments/work_retrieve_params.rb +10 -1
- data/lib/anthropic/models/beta/environments/work_stats_params.rb +10 -1
- data/lib/anthropic/models/beta/environments/work_stop_params.rb +10 -1
- data/lib/anthropic/models/beta/environments/work_update_params.rb +10 -1
- data/lib/anthropic/models/beta/file_delete_params.rb +10 -1
- data/lib/anthropic/models/beta/file_download_params.rb +10 -1
- data/lib/anthropic/models/beta/file_list_params.rb +7 -1
- data/lib/anthropic/models/beta/file_retrieve_metadata_params.rb +10 -1
- data/lib/anthropic/models/beta/file_upload_params.rb +7 -1
- data/lib/anthropic/models/beta/memory_store_archive_params.rb +14 -2
- data/lib/anthropic/models/beta/memory_store_create_params.rb +7 -1
- data/lib/anthropic/models/beta/memory_store_delete_params.rb +14 -2
- data/lib/anthropic/models/beta/memory_store_list_params.rb +7 -1
- data/lib/anthropic/models/beta/memory_store_retrieve_params.rb +13 -2
- data/lib/anthropic/models/beta/memory_store_update_params.rb +11 -2
- data/lib/anthropic/models/beta/memory_stores/beta_managed_agents_error.rb +15 -3
- data/lib/anthropic/models/beta/memory_stores/beta_managed_agents_memory_path_conflict_error.rb +26 -3
- data/lib/anthropic/models/beta/memory_stores/beta_managed_agents_memory_precondition_failed_error.rb +14 -1
- data/lib/anthropic/models/beta/memory_stores/memory_create_params.rb +15 -4
- data/lib/anthropic/models/beta/memory_stores/memory_delete_params.rb +20 -5
- data/lib/anthropic/models/beta/memory_stores/memory_list_params.rb +9 -2
- data/lib/anthropic/models/beta/memory_stores/memory_retrieve_params.rb +20 -5
- data/lib/anthropic/models/beta/memory_stores/memory_update_params.rb +17 -5
- data/lib/anthropic/models/beta/memory_stores/memory_version_list_params.rb +37 -18
- data/lib/anthropic/models/beta/memory_stores/memory_version_redact_params.rb +15 -3
- data/lib/anthropic/models/beta/memory_stores/memory_version_retrieve_params.rb +21 -5
- data/lib/anthropic/models/beta/message_count_tokens_params.rb +7 -1
- data/lib/anthropic/models/beta/message_create_params.rb +7 -1
- data/lib/anthropic/models/beta/messages/batch_cancel_params.rb +10 -1
- data/lib/anthropic/models/beta/messages/batch_create_params.rb +7 -1
- data/lib/anthropic/models/beta/messages/batch_delete_params.rb +10 -1
- data/lib/anthropic/models/beta/messages/batch_list_params.rb +7 -1
- data/lib/anthropic/models/beta/messages/batch_results_params.rb +10 -1
- data/lib/anthropic/models/beta/messages/batch_retrieve_params.rb +10 -1
- data/lib/anthropic/models/beta/model_list_params.rb +7 -1
- data/lib/anthropic/models/beta/model_retrieve_params.rb +10 -1
- data/lib/anthropic/models/beta/session_archive_params.rb +10 -1
- data/lib/anthropic/models/beta/session_create_params.rb +7 -1
- data/lib/anthropic/models/beta/session_delete_params.rb +10 -1
- data/lib/anthropic/models/beta/session_list_params.rb +7 -1
- data/lib/anthropic/models/beta/session_retrieve_params.rb +10 -1
- data/lib/anthropic/models/beta/session_update_params.rb +7 -1
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_agent_evaluated_permission.rb +21 -0
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_agent_mcp_tool_use_event.rb +3 -17
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_agent_tool_use_event.rb +3 -17
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_session_event.rb +1 -1
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_session_thread.rb +3 -9
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_stream_session_events.rb +1 -1
- data/lib/anthropic/models/beta/sessions/beta_managed_agents_stream_session_thread_events.rb +1 -1
- data/lib/anthropic/models/beta/sessions/event_list_params.rb +8 -3
- data/lib/anthropic/models/beta/sessions/event_send_params.rb +10 -1
- data/lib/anthropic/models/beta/sessions/event_stream_params.rb +7 -1
- data/lib/anthropic/models/beta/sessions/resource_add_params.rb +10 -1
- data/lib/anthropic/models/beta/sessions/resource_delete_params.rb +10 -1
- data/lib/anthropic/models/beta/sessions/resource_list_params.rb +7 -1
- data/lib/anthropic/models/beta/sessions/resource_retrieve_params.rb +10 -1
- data/lib/anthropic/models/beta/sessions/resource_update_params.rb +7 -1
- data/lib/anthropic/models/beta/sessions/thread_archive_params.rb +10 -1
- data/lib/anthropic/models/beta/sessions/thread_list_params.rb +10 -1
- data/lib/anthropic/models/beta/sessions/thread_retrieve_params.rb +10 -1
- data/lib/anthropic/models/beta/sessions/threads/event_list_params.rb +12 -5
- data/lib/anthropic/models/beta/sessions/threads/event_stream_params.rb +7 -1
- data/lib/anthropic/models/beta/skill_create_params.rb +7 -1
- data/lib/anthropic/models/beta/skill_delete_params.rb +7 -1
- data/lib/anthropic/models/beta/skill_list_params.rb +7 -1
- data/lib/anthropic/models/beta/skill_retrieve_params.rb +7 -1
- data/lib/anthropic/models/beta/skills/version_create_params.rb +7 -1
- data/lib/anthropic/models/beta/skills/version_delete_params.rb +7 -1
- data/lib/anthropic/models/beta/skills/version_download_params.rb +7 -1
- data/lib/anthropic/models/beta/skills/version_list_params.rb +7 -1
- data/lib/anthropic/models/beta/skills/version_retrieve_params.rb +7 -1
- data/lib/anthropic/models/beta/tunnel_archive_params.rb +12 -2
- data/lib/anthropic/models/beta/tunnel_create_params.rb +10 -1
- data/lib/anthropic/models/beta/tunnel_list_params.rb +10 -1
- data/lib/anthropic/models/beta/tunnel_retrieve_params.rb +12 -2
- data/lib/anthropic/models/beta/tunnel_reveal_token_params.rb +12 -2
- data/lib/anthropic/models/beta/tunnel_rotate_token_params.rb +12 -2
- data/lib/anthropic/models/beta/tunnels/certificate_archive_params.rb +14 -3
- data/lib/anthropic/models/beta/tunnels/certificate_create_params.rb +9 -2
- data/lib/anthropic/models/beta/tunnels/certificate_list_params.rb +9 -2
- data/lib/anthropic/models/beta/tunnels/certificate_retrieve_params.rb +14 -3
- data/lib/anthropic/models/beta/user_profile_create_enrollment_url_params.rb +13 -2
- data/lib/anthropic/models/beta/user_profile_create_params.rb +10 -1
- data/lib/anthropic/models/beta/user_profile_list_params.rb +33 -11
- data/lib/anthropic/models/beta/user_profile_retrieve_params.rb +12 -2
- data/lib/anthropic/models/beta/user_profile_update_params.rb +12 -2
- data/lib/anthropic/models/beta/vault_archive_params.rb +12 -2
- data/lib/anthropic/models/beta/vault_create_params.rb +7 -1
- data/lib/anthropic/models/beta/vault_delete_params.rb +12 -2
- data/lib/anthropic/models/beta/vault_list_params.rb +10 -1
- data/lib/anthropic/models/beta/vault_retrieve_params.rb +12 -2
- data/lib/anthropic/models/beta/vault_update_params.rb +9 -2
- data/lib/anthropic/models/beta/vaults/credential_archive_params.rb +14 -3
- data/lib/anthropic/models/beta/vaults/credential_create_params.rb +9 -2
- data/lib/anthropic/models/beta/vaults/credential_delete_params.rb +14 -3
- data/lib/anthropic/models/beta/vaults/credential_list_params.rb +12 -2
- data/lib/anthropic/models/beta/vaults/credential_mcp_oauth_validate_params.rb +15 -3
- data/lib/anthropic/models/beta/vaults/credential_retrieve_params.rb +14 -3
- data/lib/anthropic/models/beta/vaults/credential_update_params.rb +11 -3
- data/lib/anthropic/models/completion_create_params.rb +7 -1
- data/lib/anthropic/models/file_delete_params.rb +10 -1
- data/lib/anthropic/models/file_download_params.rb +10 -1
- data/lib/anthropic/models/file_list_params.rb +7 -1
- data/lib/anthropic/models/file_retrieve_metadata_params.rb +10 -1
- data/lib/anthropic/models/file_upload_params.rb +7 -1
- data/lib/anthropic/models/message_count_tokens_params.rb +7 -1
- data/lib/anthropic/models/message_create_params.rb +7 -1
- data/lib/anthropic/models/messages/batch_cancel_params.rb +10 -1
- data/lib/anthropic/models/messages/batch_create_params.rb +7 -1
- data/lib/anthropic/models/messages/batch_delete_params.rb +10 -1
- data/lib/anthropic/models/messages/batch_list_params.rb +7 -1
- data/lib/anthropic/models/messages/batch_results_params.rb +10 -1
- data/lib/anthropic/models/messages/batch_retrieve_params.rb +10 -1
- data/lib/anthropic/models/model.rb +5 -0
- data/lib/anthropic/models/model_list_params.rb +7 -1
- data/lib/anthropic/models/model_retrieve_params.rb +10 -1
- data/lib/anthropic/models/skill_create_params.rb +7 -1
- data/lib/anthropic/models/skill_delete_params.rb +7 -1
- data/lib/anthropic/models/skill_list_params.rb +7 -1
- data/lib/anthropic/models/skill_retrieve_params.rb +7 -1
- data/lib/anthropic/models/skills/version_create_params.rb +7 -1
- data/lib/anthropic/models/skills/version_delete_params.rb +7 -1
- data/lib/anthropic/models/skills/version_list_params.rb +7 -1
- data/lib/anthropic/models/skills/version_retrieve_params.rb +7 -1
- data/lib/anthropic/resources/beta/dreams.rb +58 -18
- data/lib/anthropic/resources/beta/memory_stores/memories.rb +12 -12
- data/lib/anthropic/resources/beta/memory_stores/memory_versions.rb +15 -14
- data/lib/anthropic/resources/beta/sessions/events.rb +4 -4
- data/lib/anthropic/resources/beta/sessions/resources.rb +8 -8
- data/lib/anthropic/resources/beta/sessions/threads/events.rb +6 -6
- data/lib/anthropic/resources/beta/sessions/threads.rb +5 -5
- data/lib/anthropic/resources/beta/sessions.rb +4 -4
- data/lib/anthropic/resources/beta/user_profiles.rb +7 -7
- data/lib/anthropic/version.rb +1 -1
- data/lib/anthropic.rb +15 -0
- data/rbi/anthropic/helpers/tools/runner.rbi +29 -0
- data/rbi/anthropic/models/anthropic_beta.rbi +7 -0
- data/rbi/anthropic/models/beta/agent_archive_params.rbi +14 -0
- data/rbi/anthropic/models/beta/agent_create_params.rbi +12 -0
- data/rbi/anthropic/models/beta/agent_list_params.rbi +12 -0
- data/rbi/anthropic/models/beta/agent_retrieve_params.rbi +14 -0
- data/rbi/anthropic/models/beta/agent_update_params.rbi +14 -0
- data/rbi/anthropic/models/beta/agents/version_list_params.rbi +14 -0
- data/rbi/anthropic/models/beta/beta_compaction_block.rbi +124 -1
- data/rbi/anthropic/models/beta/beta_compaction_block_param.rbi +132 -1
- data/rbi/anthropic/models/beta/beta_content_block.rbi +27 -3
- data/rbi/anthropic/models/beta/beta_content_block_param.rbi +37 -3
- data/rbi/anthropic/models/beta/beta_diagnostics.rbi +2 -2
- data/rbi/anthropic/models/beta/beta_dream.rbi +103 -14
- data/rbi/anthropic/models/beta/beta_dream_error.rbi +16 -1
- data/rbi/anthropic/models/beta/beta_dream_input.rbi +18 -1
- data/rbi/anthropic/models/beta/beta_dream_memory_store_input.rbi +16 -4
- data/rbi/anthropic/models/beta/beta_dream_memory_store_output.rbi +13 -2
- data/rbi/anthropic/models/beta/beta_dream_model_config.rbi +8 -4
- data/rbi/anthropic/models/beta/beta_dream_model_config_param.rbi +15 -3
- data/rbi/anthropic/models/beta/beta_dream_output.rbi +13 -2
- data/rbi/anthropic/models/beta/beta_dream_sessions_input.rbi +21 -2
- data/rbi/anthropic/models/beta/beta_dream_status.rbi +11 -2
- data/rbi/anthropic/models/beta/beta_dream_usage.rbi +20 -9
- data/rbi/anthropic/models/beta/beta_dreaming_error.rbi +2 -2
- data/rbi/anthropic/models/beta/beta_managed_agents_model.rbi +7 -0
- data/rbi/anthropic/models/beta/beta_mcp_tool.rbi +52 -0
- data/rbi/anthropic/models/beta/beta_mcp_tool_listing_block.rbi +53 -0
- data/rbi/anthropic/models/beta/beta_mcp_tool_listing_block_param.rbi +62 -0
- data/rbi/anthropic/models/beta/beta_mcp_tool_param.rbi +62 -0
- data/rbi/anthropic/models/beta/beta_mcp_toolset.rbi +16 -1
- data/rbi/anthropic/models/beta/beta_message.rbi +6 -5
- data/rbi/anthropic/models/beta/beta_output_behavior.rbi +9 -1
- data/rbi/anthropic/models/beta/beta_output_behavior_create_new.rbi +5 -3
- data/rbi/anthropic/models/beta/beta_output_behavior_update_existing.rbi +15 -4
- data/rbi/anthropic/models/beta/beta_raw_content_block_start_event.rbi +29 -4
- data/rbi/anthropic/models/beta/beta_raw_message_stream_event.rbi +2 -1
- data/rbi/anthropic/models/beta/beta_request_tool_addition_block.rbi +54 -9
- data/rbi/anthropic/models/beta/beta_request_tool_removal_block.rbi +3 -2
- data/rbi/anthropic/models/beta/beta_response_tool.rbi +255 -0
- data/rbi/anthropic/models/beta/beta_response_tool_addition_block.rbi +182 -0
- data/rbi/anthropic/models/beta/beta_response_tool_change_mcp_tool_reference.rbi +46 -0
- data/rbi/anthropic/models/beta/beta_response_tool_change_mcp_toolset_reference.rbi +38 -0
- data/rbi/anthropic/models/beta/beta_response_tool_change_tool_reference.rbi +38 -0
- data/rbi/anthropic/models/beta/beta_response_tool_input_schema.rbi +54 -0
- data/rbi/anthropic/models/beta/beta_response_tool_removal_block.rbi +139 -0
- data/rbi/anthropic/models/beta/beta_response_tool_union.rbi +55 -0
- data/rbi/anthropic/models/beta/beta_target_store_held_error.rbi +14 -11
- data/rbi/anthropic/models/beta/beta_tool_change_tool_definition.rbi +78 -0
- data/rbi/anthropic/models/beta/beta_tool_change_tool_definition_param.rbi +141 -0
- data/rbi/anthropic/models/beta/beta_tool_change_tool_reference.rbi +3 -2
- data/rbi/anthropic/models/beta/beta_user_profile.rbi +10 -0
- data/rbi/anthropic/models/beta/beta_user_profile_enrollment_url.rbi +2 -0
- data/rbi/anthropic/models/beta/beta_user_profile_external_user_details.rbi +5 -0
- data/rbi/anthropic/models/beta/beta_user_profile_external_user_details_params.rbi +5 -0
- data/rbi/anthropic/models/beta/beta_user_profile_trust_grant.rbi +2 -0
- data/rbi/anthropic/models/beta/deployment_archive_params.rbi +14 -0
- data/rbi/anthropic/models/beta/deployment_create_params.rbi +12 -0
- data/rbi/anthropic/models/beta/deployment_list_params.rbi +12 -0
- data/rbi/anthropic/models/beta/deployment_pause_params.rbi +14 -0
- data/rbi/anthropic/models/beta/deployment_retrieve_params.rbi +14 -0
- data/rbi/anthropic/models/beta/deployment_run_list_params.rbi +12 -0
- data/rbi/anthropic/models/beta/deployment_run_params.rbi +14 -0
- data/rbi/anthropic/models/beta/deployment_run_retrieve_params.rbi +14 -0
- data/rbi/anthropic/models/beta/deployment_unpause_params.rbi +14 -0
- data/rbi/anthropic/models/beta/deployment_update_params.rbi +14 -0
- data/rbi/anthropic/models/beta/dream_archive_params.rbi +14 -0
- data/rbi/anthropic/models/beta/dream_cancel_params.rbi +14 -0
- data/rbi/anthropic/models/beta/dream_create_params.rbi +56 -0
- data/rbi/anthropic/models/beta/dream_list_params.rbi +36 -18
- data/rbi/anthropic/models/beta/dream_retrieve_params.rbi +14 -0
- data/rbi/anthropic/models/beta/environment_archive_params.rbi +12 -0
- data/rbi/anthropic/models/beta/environment_create_params.rbi +12 -0
- data/rbi/anthropic/models/beta/environment_delete_params.rbi +12 -0
- data/rbi/anthropic/models/beta/environment_list_params.rbi +12 -0
- data/rbi/anthropic/models/beta/environment_retrieve_params.rbi +12 -0
- data/rbi/anthropic/models/beta/environment_update_params.rbi +12 -0
- data/rbi/anthropic/models/beta/environments/work_retrieve_params.rbi +12 -0
- data/rbi/anthropic/models/beta/environments/work_stats_params.rbi +12 -0
- data/rbi/anthropic/models/beta/environments/work_stop_params.rbi +12 -0
- data/rbi/anthropic/models/beta/environments/work_update_params.rbi +12 -0
- data/rbi/anthropic/models/beta/file_delete_params.rbi +12 -0
- data/rbi/anthropic/models/beta/file_download_params.rbi +12 -0
- data/rbi/anthropic/models/beta/file_list_params.rbi +12 -0
- data/rbi/anthropic/models/beta/file_retrieve_metadata_params.rbi +12 -0
- data/rbi/anthropic/models/beta/file_upload_params.rbi +12 -0
- data/rbi/anthropic/models/beta/memory_store_archive_params.rbi +18 -0
- data/rbi/anthropic/models/beta/memory_store_create_params.rbi +12 -0
- data/rbi/anthropic/models/beta/memory_store_delete_params.rbi +18 -0
- data/rbi/anthropic/models/beta/memory_store_list_params.rbi +12 -0
- data/rbi/anthropic/models/beta/memory_store_retrieve_params.rbi +16 -0
- data/rbi/anthropic/models/beta/memory_store_update_params.rbi +18 -0
- data/rbi/anthropic/models/beta/memory_stores/beta_managed_agents_error.rbi +7 -0
- data/rbi/anthropic/models/beta/memory_stores/beta_managed_agents_memory_path_conflict_error.rbi +23 -0
- data/rbi/anthropic/models/beta/memory_stores/beta_managed_agents_memory_precondition_failed_error.rbi +16 -1
- data/rbi/anthropic/models/beta/memory_stores/memory_create_params.rbi +24 -2
- data/rbi/anthropic/models/beta/memory_stores/memory_delete_params.rbi +26 -2
- data/rbi/anthropic/models/beta/memory_stores/memory_list_params.rbi +14 -0
- data/rbi/anthropic/models/beta/memory_stores/memory_retrieve_params.rbi +26 -2
- data/rbi/anthropic/models/beta/memory_stores/memory_update_params.rbi +26 -2
- data/rbi/anthropic/models/beta/memory_stores/memory_version_list_params.rbi +46 -16
- data/rbi/anthropic/models/beta/memory_stores/memory_version_redact_params.rbi +16 -0
- data/rbi/anthropic/models/beta/memory_stores/memory_version_retrieve_params.rbi +26 -2
- data/rbi/anthropic/models/beta/message_count_tokens_params.rbi +12 -0
- data/rbi/anthropic/models/beta/message_create_params.rbi +12 -0
- data/rbi/anthropic/models/beta/messages/batch_cancel_params.rbi +12 -0
- data/rbi/anthropic/models/beta/messages/batch_create_params.rbi +12 -0
- data/rbi/anthropic/models/beta/messages/batch_delete_params.rbi +12 -0
- data/rbi/anthropic/models/beta/messages/batch_list_params.rbi +12 -0
- data/rbi/anthropic/models/beta/messages/batch_results_params.rbi +12 -0
- data/rbi/anthropic/models/beta/messages/batch_retrieve_params.rbi +12 -0
- data/rbi/anthropic/models/beta/model_list_params.rbi +12 -0
- data/rbi/anthropic/models/beta/model_retrieve_params.rbi +12 -0
- data/rbi/anthropic/models/beta/session_archive_params.rbi +12 -0
- data/rbi/anthropic/models/beta/session_create_params.rbi +12 -0
- data/rbi/anthropic/models/beta/session_delete_params.rbi +12 -0
- data/rbi/anthropic/models/beta/session_list_params.rbi +12 -0
- data/rbi/anthropic/models/beta/session_retrieve_params.rbi +12 -0
- data/rbi/anthropic/models/beta/session_update_params.rbi +12 -0
- data/rbi/anthropic/models/beta/sessions/beta_managed_agents_agent_evaluated_permission.rbi +49 -0
- data/rbi/anthropic/models/beta/sessions/beta_managed_agents_agent_mcp_tool_use_event.rbi +4 -44
- data/rbi/anthropic/models/beta/sessions/beta_managed_agents_agent_tool_use_event.rbi +4 -44
- data/rbi/anthropic/models/beta/sessions/beta_managed_agents_session_event.rbi +1 -4
- data/rbi/anthropic/models/beta/sessions/beta_managed_agents_session_thread.rbi +3 -6
- data/rbi/anthropic/models/beta/sessions/beta_managed_agents_stream_session_events.rbi +1 -4
- data/rbi/anthropic/models/beta/sessions/beta_managed_agents_stream_session_thread_events.rbi +1 -4
- data/rbi/anthropic/models/beta/sessions/event_list_params.rbi +12 -2
- data/rbi/anthropic/models/beta/sessions/event_send_params.rbi +12 -0
- data/rbi/anthropic/models/beta/sessions/event_stream_params.rbi +12 -0
- data/rbi/anthropic/models/beta/sessions/resource_add_params.rbi +12 -0
- data/rbi/anthropic/models/beta/sessions/resource_delete_params.rbi +12 -0
- data/rbi/anthropic/models/beta/sessions/resource_list_params.rbi +12 -0
- data/rbi/anthropic/models/beta/sessions/resource_retrieve_params.rbi +12 -0
- data/rbi/anthropic/models/beta/sessions/resource_update_params.rbi +12 -0
- data/rbi/anthropic/models/beta/sessions/thread_archive_params.rbi +12 -0
- data/rbi/anthropic/models/beta/sessions/thread_list_params.rbi +12 -0
- data/rbi/anthropic/models/beta/sessions/thread_retrieve_params.rbi +12 -0
- data/rbi/anthropic/models/beta/sessions/threads/event_list_params.rbi +12 -4
- data/rbi/anthropic/models/beta/sessions/threads/event_stream_params.rbi +12 -0
- data/rbi/anthropic/models/beta/skill_create_params.rbi +12 -0
- data/rbi/anthropic/models/beta/skill_delete_params.rbi +12 -0
- data/rbi/anthropic/models/beta/skill_list_params.rbi +12 -0
- data/rbi/anthropic/models/beta/skill_retrieve_params.rbi +12 -0
- data/rbi/anthropic/models/beta/skills/version_create_params.rbi +12 -0
- data/rbi/anthropic/models/beta/skills/version_delete_params.rbi +12 -0
- data/rbi/anthropic/models/beta/skills/version_download_params.rbi +12 -0
- data/rbi/anthropic/models/beta/skills/version_list_params.rbi +12 -0
- data/rbi/anthropic/models/beta/skills/version_retrieve_params.rbi +12 -0
- data/rbi/anthropic/models/beta/tunnel_archive_params.rbi +14 -0
- data/rbi/anthropic/models/beta/tunnel_create_params.rbi +12 -0
- data/rbi/anthropic/models/beta/tunnel_list_params.rbi +12 -0
- data/rbi/anthropic/models/beta/tunnel_retrieve_params.rbi +14 -0
- data/rbi/anthropic/models/beta/tunnel_reveal_token_params.rbi +14 -0
- data/rbi/anthropic/models/beta/tunnel_rotate_token_params.rbi +14 -0
- data/rbi/anthropic/models/beta/tunnels/certificate_archive_params.rbi +16 -0
- data/rbi/anthropic/models/beta/tunnels/certificate_create_params.rbi +14 -0
- data/rbi/anthropic/models/beta/tunnels/certificate_list_params.rbi +14 -0
- data/rbi/anthropic/models/beta/tunnels/certificate_retrieve_params.rbi +16 -0
- data/rbi/anthropic/models/beta/user_profile_create_enrollment_url_params.rbi +14 -0
- data/rbi/anthropic/models/beta/user_profile_create_params.rbi +15 -0
- data/rbi/anthropic/models/beta/user_profile_list_params.rbi +40 -10
- data/rbi/anthropic/models/beta/user_profile_retrieve_params.rbi +14 -0
- data/rbi/anthropic/models/beta/user_profile_update_params.rbi +17 -0
- data/rbi/anthropic/models/beta/vault_archive_params.rbi +14 -0
- data/rbi/anthropic/models/beta/vault_create_params.rbi +12 -0
- data/rbi/anthropic/models/beta/vault_delete_params.rbi +14 -0
- data/rbi/anthropic/models/beta/vault_list_params.rbi +12 -0
- data/rbi/anthropic/models/beta/vault_retrieve_params.rbi +14 -0
- data/rbi/anthropic/models/beta/vault_update_params.rbi +14 -0
- data/rbi/anthropic/models/beta/vaults/credential_archive_params.rbi +16 -0
- data/rbi/anthropic/models/beta/vaults/credential_create_params.rbi +14 -0
- data/rbi/anthropic/models/beta/vaults/credential_delete_params.rbi +16 -0
- data/rbi/anthropic/models/beta/vaults/credential_list_params.rbi +14 -0
- data/rbi/anthropic/models/beta/vaults/credential_mcp_oauth_validate_params.rbi +16 -0
- data/rbi/anthropic/models/beta/vaults/credential_retrieve_params.rbi +16 -0
- data/rbi/anthropic/models/beta/vaults/credential_update_params.rbi +16 -0
- data/rbi/anthropic/models/completion_create_params.rbi +12 -0
- data/rbi/anthropic/models/file_delete_params.rbi +12 -0
- data/rbi/anthropic/models/file_download_params.rbi +12 -0
- data/rbi/anthropic/models/file_list_params.rbi +12 -0
- data/rbi/anthropic/models/file_retrieve_metadata_params.rbi +12 -0
- data/rbi/anthropic/models/file_upload_params.rbi +12 -0
- data/rbi/anthropic/models/message_count_tokens_params.rbi +12 -0
- data/rbi/anthropic/models/message_create_params.rbi +12 -0
- data/rbi/anthropic/models/messages/batch_cancel_params.rbi +12 -0
- data/rbi/anthropic/models/messages/batch_create_params.rbi +12 -0
- data/rbi/anthropic/models/messages/batch_delete_params.rbi +12 -0
- data/rbi/anthropic/models/messages/batch_list_params.rbi +12 -0
- data/rbi/anthropic/models/messages/batch_results_params.rbi +12 -0
- data/rbi/anthropic/models/messages/batch_retrieve_params.rbi +12 -0
- data/rbi/anthropic/models/model.rbi +4 -0
- data/rbi/anthropic/models/model_list_params.rbi +12 -0
- data/rbi/anthropic/models/model_retrieve_params.rbi +12 -0
- data/rbi/anthropic/models/skill_create_params.rbi +12 -0
- data/rbi/anthropic/models/skill_delete_params.rbi +12 -0
- data/rbi/anthropic/models/skill_list_params.rbi +12 -0
- data/rbi/anthropic/models/skill_retrieve_params.rbi +12 -0
- data/rbi/anthropic/models/skills/version_create_params.rbi +12 -0
- data/rbi/anthropic/models/skills/version_delete_params.rbi +12 -0
- data/rbi/anthropic/models/skills/version_list_params.rbi +12 -0
- data/rbi/anthropic/models/skills/version_retrieve_params.rbi +12 -0
- data/rbi/anthropic/resources/beta/dreams.rbi +81 -21
- data/rbi/anthropic/resources/beta/memory_stores/memories.rbi +29 -12
- data/rbi/anthropic/resources/beta/memory_stores/memory_versions.rbi +28 -14
- data/rbi/anthropic/resources/beta/sessions/events.rbi +4 -4
- data/rbi/anthropic/resources/beta/sessions/resources.rbi +8 -8
- data/rbi/anthropic/resources/beta/sessions/threads/events.rbi +6 -6
- data/rbi/anthropic/resources/beta/sessions/threads.rbi +5 -5
- data/rbi/anthropic/resources/beta/sessions.rbi +1 -4
- data/rbi/anthropic/resources/beta/user_profiles.rbi +13 -7
- data/sig/anthropic/models/anthropic_beta.rbs +4 -0
- data/sig/anthropic/models/beta/beta_compaction_block.rbs +44 -2
- data/sig/anthropic/models/beta/beta_compaction_block_param.rbs +47 -2
- data/sig/anthropic/models/beta/beta_content_block.rbs +14 -2
- data/sig/anthropic/models/beta/beta_content_block_param.rbs +13 -1
- data/sig/anthropic/models/beta/beta_dream_status.rbs +3 -1
- data/sig/anthropic/models/beta/beta_managed_agents_model.rbs +5 -1
- data/sig/anthropic/models/beta/beta_mcp_tool.rbs +32 -0
- data/sig/anthropic/models/beta/beta_mcp_tool_listing_block.rbs +34 -0
- data/sig/anthropic/models/beta/beta_mcp_tool_listing_block_param.rbs +34 -0
- data/sig/anthropic/models/beta/beta_mcp_tool_param.rbs +34 -0
- data/sig/anthropic/models/beta/beta_mcp_toolset.rbs +7 -2
- data/sig/anthropic/models/beta/beta_raw_content_block_start_event.rbs +14 -2
- data/sig/anthropic/models/beta/beta_request_tool_addition_block.rbs +12 -2
- data/sig/anthropic/models/beta/beta_response_tool.rbs +105 -0
- data/sig/anthropic/models/beta/beta_response_tool_addition_block.rbs +84 -0
- data/sig/anthropic/models/beta/beta_response_tool_change_mcp_tool_reference.rbs +30 -0
- data/sig/anthropic/models/beta/beta_response_tool_change_mcp_toolset_reference.rbs +23 -0
- data/sig/anthropic/models/beta/beta_response_tool_change_tool_reference.rbs +20 -0
- data/sig/anthropic/models/beta/beta_response_tool_input_schema.rbs +34 -0
- data/sig/anthropic/models/beta/beta_response_tool_removal_block.rbs +74 -0
- data/sig/anthropic/models/beta/beta_response_tool_union.rbs +43 -0
- data/sig/anthropic/models/beta/beta_tool_change_tool_definition.rbs +29 -0
- data/sig/anthropic/models/beta/beta_tool_change_tool_definition_param.rbs +29 -0
- data/sig/anthropic/models/beta/beta_user_profile.rbs +3 -0
- data/sig/anthropic/models/beta/beta_user_profile_external_user_details.rbs +5 -0
- data/sig/anthropic/models/beta/beta_user_profile_external_user_details_params.rbs +5 -0
- data/sig/anthropic/models/beta/sessions/beta_managed_agents_agent_evaluated_permission.rbs +20 -0
- data/sig/anthropic/models/beta/sessions/beta_managed_agents_agent_mcp_tool_use_event.rbs +6 -18
- data/sig/anthropic/models/beta/sessions/beta_managed_agents_agent_tool_use_event.rbs +6 -18
- data/sig/anthropic/models/beta/sessions/beta_managed_agents_session_event.rbs +3 -4
- data/sig/anthropic/models/beta/sessions/beta_managed_agents_stream_session_events.rbs +3 -4
- data/sig/anthropic/models/beta/sessions/beta_managed_agents_stream_session_thread_events.rbs +3 -4
- data/sig/anthropic/models/beta/user_profile_create_params.rbs +3 -0
- data/sig/anthropic/models/beta/user_profile_list_params.rbs +6 -0
- data/sig/anthropic/models/beta/user_profile_update_params.rbs +3 -0
- data/sig/anthropic/models/model.rbs +4 -0
- metadata +47 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b0814f7989dfdce90cdc7535edcba2765bcbb40ed802424357334ff1087e860e
|
|
4
|
+
data.tar.gz: b3eef636f0f74f2d42c8d56c784461214c2575616afc4fbf5750f95affb325a0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '0668735fb6de38f7ca8f71985eb642a7ec67b770317604c6a4bbfd5685a57aa6c4caf3c919b6571247c99ba51bdf6419ce59329b1e4ae6070ad271a8e7559fe4'
|
|
7
|
+
data.tar.gz: 237c52d786dbfe007938ad70ec8c54e888fad60bcab49c0f2eb48b4ad082252ddd2fbc76c65e7b777385efd0fe89775bf3c9f9e7dcc82ddc4847ceb1bf130930
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.73.0 (2026-09-22)
|
|
4
|
+
|
|
5
|
+
Full Changelog: [v1.72.0...v1.73.0](https://github.com/anthropics/anthropic-sdk-ruby/compare/v1.72.0...v1.73.0)
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
* **api:** add support for claude-opus-5-5, inline tool definitions and MCP tool-list pinning (beta) ([b68ad25](https://github.com/anthropics/anthropic-sdk-ruby/commit/b68ad25d7e21c929b0a2309ba5c8ecc48f09fcfa))
|
|
10
|
+
* **tools:** add compact_before_next_turn() to the tool runner ([#258](https://github.com/anthropics/anthropic-sdk-ruby/issues/258)) ([adccb26](https://github.com/anthropics/anthropic-sdk-ruby/commit/adccb26c933e2057794f903e41308d65108ecaff))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* **api:** share one evaluated_permission enum across Managed Agents events ([5cea62a](https://github.com/anthropics/anthropic-sdk-ruby/commit/5cea62a855bec9f4cc991b2309b6934b9db987bf))
|
|
16
|
+
* **tools:** add_tools takes effect straight away ([#269](https://github.com/anthropics/anthropic-sdk-ruby/issues/269)) ([289bfad](https://github.com/anthropics/anthropic-sdk-ruby/commit/289bfad23d1d26d0b86006f9aca7a624f8a86ce6))
|
|
17
|
+
* **tools:** leave reply-only params off the tool runner's compaction request ([#267](https://github.com/anthropics/anthropic-sdk-ruby/issues/267)) ([5a1d7d2](https://github.com/anthropics/anthropic-sdk-ruby/commit/5a1d7d2352e7e4f65c312219c7a5695187ea2926))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Chores
|
|
21
|
+
|
|
22
|
+
* **ci:** give the lint and breaking-change detection jobs more time ([59fc172](https://github.com/anthropics/anthropic-sdk-ruby/commit/59fc172c0f462de5743e947b6ec3c4708a5aac58))
|
|
23
|
+
* **docs:** add descriptions to the Dreams API reference ([cfc7239](https://github.com/anthropics/anthropic-sdk-ruby/commit/cfc7239c607941094a470586342ed77cee41d75c))
|
|
24
|
+
* **docs:** add descriptions to the User Profiles API reference ([cfc7239](https://github.com/anthropics/anthropic-sdk-ruby/commit/cfc7239c607941094a470586342ed77cee41d75c))
|
|
25
|
+
* **docs:** add memory store descriptions to the Managed Agents API reference ([cfc7239](https://github.com/anthropics/anthropic-sdk-ruby/commit/cfc7239c607941094a470586342ed77cee41d75c))
|
|
26
|
+
* **docs:** improve descriptions in the Dreams API reference ([54a81a7](https://github.com/anthropics/anthropic-sdk-ruby/commit/54a81a7c9f7fce043fafb342014144bf2a1bf050))
|
|
27
|
+
* **docs:** simplify the session thread agent type description ([23d1d44](https://github.com/anthropics/anthropic-sdk-ruby/commit/23d1d4418dcf305366c48f144756071f173f909b))
|
|
28
|
+
* **docs:** update diagnostics field descriptions on beta messages ([678a792](https://github.com/anthropics/anthropic-sdk-ruby/commit/678a7923359f8de6be74cffd9bbd1123df5e2cb9))
|
|
29
|
+
* **internal:** let the typecheck task use every core, up to 16 ([f0ac300](https://github.com/anthropics/anthropic-sdk-ruby/commit/f0ac30052d083a8bf95c66a7c98a80985649c70d))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### Documentation
|
|
33
|
+
|
|
34
|
+
* add path and header parameter descriptions ([d458058](https://github.com/anthropics/anthropic-sdk-ruby/commit/d458058bfe901b540f5b346af63926d344c253dd))
|
|
35
|
+
|
|
3
36
|
## 1.72.0 (2026-09-18)
|
|
4
37
|
|
|
5
38
|
Full Changelog: [v1.71.0...v1.72.0](https://github.com/anthropics/anthropic-sdk-ruby/compare/v1.71.0...v1.72.0)
|
data/README.md
CHANGED
|
@@ -15,7 +15,7 @@ Add to your application's Gemfile:
|
|
|
15
15
|
<!-- x-release-please-start-version -->
|
|
16
16
|
|
|
17
17
|
```ruby
|
|
18
|
-
gem "anthropic", "~> 1.
|
|
18
|
+
gem "anthropic", "~> 1.73.0"
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
<!-- x-release-please-end -->
|
|
@@ -33,7 +33,7 @@ anthropic = Anthropic::Client.new(
|
|
|
33
33
|
message = anthropic.messages.create(
|
|
34
34
|
max_tokens: 1024,
|
|
35
35
|
messages: [{role: "user", content: "Hello, Claude"}],
|
|
36
|
-
model: "claude-opus-
|
|
36
|
+
model: "claude-opus-5-5"
|
|
37
37
|
)
|
|
38
38
|
|
|
39
39
|
puts(message.content)
|
|
@@ -35,54 +35,29 @@ module Anthropic
|
|
|
35
35
|
|
|
36
36
|
case data
|
|
37
37
|
in {tools: Array => tool_array}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
definition.tap { _1.update(strict:) if strict }
|
|
56
|
-
# Input schema class used directly as a tool:
|
|
57
|
-
in Anthropic::Helpers::InputSchema::JsonSchemaConverter
|
|
58
|
-
name = model_name(tool.name)
|
|
59
|
-
|
|
60
|
-
description =
|
|
61
|
-
case tool
|
|
62
|
-
in Class if tool <= Anthropic::Helpers::InputSchema::BaseModel
|
|
63
|
-
tool.doc_string || name
|
|
38
|
+
tool_array.replace(tool_array.map { tool_to_param(_1, tools:, strict:) })
|
|
39
|
+
else
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# A `tool_addition` block defines a tool by value, in the shape of a `tools` entry.
|
|
43
|
+
case data
|
|
44
|
+
in {messages: Array => messages}
|
|
45
|
+
messages.each do |message|
|
|
46
|
+
case message
|
|
47
|
+
in {role: :system | "system", content: Array => blocks}
|
|
48
|
+
blocks.each do |block|
|
|
49
|
+
case block
|
|
50
|
+
in {
|
|
51
|
+
type: :tool_addition | "tool_addition",
|
|
52
|
+
tool: {type: :tool_definition | "tool_definition", definition:} => tool
|
|
53
|
+
}
|
|
54
|
+
tool.store(:definition, tool_to_param(definition, tools:, strict:))
|
|
64
55
|
else
|
|
65
|
-
name
|
|
66
56
|
end
|
|
67
|
-
|
|
68
|
-
tools.store(name, tool)
|
|
69
|
-
input_schema = Anthropic::Helpers::InputSchema::JsonSchemaConverter.to_json_schema(tool)
|
|
70
|
-
{name:, description:, input_schema:}.tap { _1.update(strict:) if strict }
|
|
71
|
-
# Tool with explicit name/description and BaseModel as input_schema:
|
|
72
|
-
in {name: String => name,
|
|
73
|
-
input_schema: Anthropic::Helpers::InputSchema::JsonSchemaConverter => tool,
|
|
74
|
-
**rest}
|
|
75
|
-
tools.store(name, tool)
|
|
76
|
-
input_schema = Anthropic::Helpers::InputSchema::JsonSchemaConverter.to_json_schema(tool)
|
|
77
|
-
rest.merge(name:, input_schema:).tap { _1.update(strict:) if strict }
|
|
57
|
+
end
|
|
78
58
|
else
|
|
79
|
-
# Any other format (pass through unchanged)
|
|
80
|
-
# This includes raw JSON schemas and any other tool definitions.
|
|
81
|
-
tool
|
|
82
59
|
end
|
|
83
60
|
end
|
|
84
|
-
# rubocop:enable Metrics/BlockLength
|
|
85
|
-
tool_array.replace(mapped)
|
|
86
61
|
else
|
|
87
62
|
end
|
|
88
63
|
|
|
@@ -212,6 +187,64 @@ module Anthropic
|
|
|
212
187
|
data[:betas] = data[:betas].to_a.dup.push("structured-outputs-2025-12-15").uniq
|
|
213
188
|
end
|
|
214
189
|
|
|
190
|
+
# @api private
|
|
191
|
+
#
|
|
192
|
+
# Convert one tool in any of the forms the helpers accept into a plain tool definition,
|
|
193
|
+
# recording under its name what `tool_use.input` is parsed back into.
|
|
194
|
+
#
|
|
195
|
+
# @param tool [Object]
|
|
196
|
+
#
|
|
197
|
+
# @param tools [Hash{String=>Class}]
|
|
198
|
+
#
|
|
199
|
+
# @param strict [Boolean, nil]
|
|
200
|
+
#
|
|
201
|
+
# @return [Object]
|
|
202
|
+
private def tool_to_param(tool, tools:, strict:)
|
|
203
|
+
case tool
|
|
204
|
+
# Runnable tool instance (an `Anthropic::BaseTool` subclass, hand-written or helper-built):
|
|
205
|
+
in Anthropic::Helpers::Tools::BaseTool
|
|
206
|
+
name = tool_api_name(tool)
|
|
207
|
+
# Helper-built tools (e.g. MCP) declare an explicit `tool_name` and only send the
|
|
208
|
+
# description they were given; hand-written tools fall back to their name.
|
|
209
|
+
description = tool.class.doc_string
|
|
210
|
+
description ||= name unless tool.class.tool_name
|
|
211
|
+
tools.store(name, tool)
|
|
212
|
+
input_schema = Anthropic::Helpers::InputSchema::JsonSchemaConverter.to_json_schema(tool)
|
|
213
|
+
# On a clash the derived keys win, so nothing in `tool_options` can shadow them.
|
|
214
|
+
definition =
|
|
215
|
+
{name:, description:, input_schema:}
|
|
216
|
+
.merge(tool.class.tool_options) { |_key, derived, _option| derived }
|
|
217
|
+
.compact
|
|
218
|
+
definition.tap { _1.update(strict:) if strict }
|
|
219
|
+
# Input schema class used directly as a tool:
|
|
220
|
+
in Anthropic::Helpers::InputSchema::JsonSchemaConverter
|
|
221
|
+
name = model_name(tool.name)
|
|
222
|
+
|
|
223
|
+
description =
|
|
224
|
+
case tool
|
|
225
|
+
in Class if tool <= Anthropic::Helpers::InputSchema::BaseModel
|
|
226
|
+
tool.doc_string || name
|
|
227
|
+
else
|
|
228
|
+
name
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
tools.store(name, tool)
|
|
232
|
+
input_schema = Anthropic::Helpers::InputSchema::JsonSchemaConverter.to_json_schema(tool)
|
|
233
|
+
{name:, description:, input_schema:}.tap { _1.update(strict:) if strict }
|
|
234
|
+
# Tool with explicit name/description and BaseModel as input_schema:
|
|
235
|
+
in {name: String => name,
|
|
236
|
+
input_schema: Anthropic::Helpers::InputSchema::JsonSchemaConverter => model,
|
|
237
|
+
**rest}
|
|
238
|
+
tools.store(name, model)
|
|
239
|
+
input_schema = Anthropic::Helpers::InputSchema::JsonSchemaConverter.to_json_schema(model)
|
|
240
|
+
rest.merge(name:, input_schema:).tap { _1.update(strict:) if strict }
|
|
241
|
+
else
|
|
242
|
+
# Any other format (pass through unchanged)
|
|
243
|
+
# This includes raw JSON schemas and any other tool definitions.
|
|
244
|
+
tool
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
|
|
215
248
|
# @api private
|
|
216
249
|
#
|
|
217
250
|
# The `name` a runnable tool is serialized under in `tools[]`.
|
|
@@ -29,7 +29,24 @@ module Anthropic
|
|
|
29
29
|
private_constant :RUN_TOOLS_STOP_REASONS, :RESUME_STOP_REASONS, :STOP_STOP_REASONS
|
|
30
30
|
|
|
31
31
|
# @return [Anthropic::Models::Beta::MessageCreateParams]
|
|
32
|
-
|
|
32
|
+
attr_reader :params
|
|
33
|
+
|
|
34
|
+
# @param params [Anthropic::Models::Beta::MessageCreateParams]
|
|
35
|
+
#
|
|
36
|
+
# @raise [ArgumentError] if `compaction` is set, if the messages are replaced while the
|
|
37
|
+
# conversation is being compacted, or if a compaction edit is added while a compaction is due
|
|
38
|
+
def params=(params)
|
|
39
|
+
reject_compaction_param!(params)
|
|
40
|
+
if @compaction_phase == :in_flight && !params[:messages].equal?(current_messages)
|
|
41
|
+
raise ArgumentError.new(
|
|
42
|
+
"Message params can't be changed while the conversation is being compacted, because the " \
|
|
43
|
+
"compaction response replaces them. Make the change on the next iteration."
|
|
44
|
+
)
|
|
45
|
+
end
|
|
46
|
+
check_can_compact!(params) if @pending_compaction || @compaction_phase == :in_flight
|
|
47
|
+
|
|
48
|
+
@params = params
|
|
49
|
+
end
|
|
33
50
|
|
|
34
51
|
# @return [Boolean]
|
|
35
52
|
def finished? = @finished
|
|
@@ -39,17 +56,75 @@ module Anthropic
|
|
|
39
56
|
self.params = {**params.to_h, messages: params[:messages].to_a + messages}
|
|
40
57
|
end
|
|
41
58
|
|
|
59
|
+
# @api public
|
|
60
|
+
#
|
|
61
|
+
# Sends the tools' definitions in `tool_addition` blocks with the next request, leaving
|
|
62
|
+
# `params[:tools]` and the prompt cache alone. A `BaseTool` is run under its name straight away,
|
|
63
|
+
# replacing a same-name tool even for a call already in the message being handled; a raw
|
|
64
|
+
# definition is never run here and stops a same-name tool from running. Needs the
|
|
65
|
+
# `inline-tools-2026-09-15` beta.
|
|
66
|
+
#
|
|
67
|
+
# @param tools [Array<Anthropic::Helpers::Tools::BaseTool, Anthropic::Models::Beta::BetaToolUnion, Hash{Symbol=>Object}>]
|
|
68
|
+
def add_tools(*tools)
|
|
69
|
+
# Converted in place, so the originals are kept apart to pair each with its definition.
|
|
70
|
+
request = {tools: tools.dup}
|
|
71
|
+
Anthropic::Helpers::Messages.distill_input_schema_models!(request, strict: nil)
|
|
72
|
+
tools.zip(request.fetch(:tools)) do |tool, definition|
|
|
73
|
+
block = {type: :tool_addition, tool: {type: :tool_definition, definition:}}
|
|
74
|
+
runnable = tool if tool.is_a?(Anthropic::Helpers::Tools::BaseTool)
|
|
75
|
+
name = changed_tool_name(block.fetch(:tool))
|
|
76
|
+
@tool_overrides.store(name, runnable) unless name.nil?
|
|
77
|
+
@pending_tool_changes << block
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# @api public
|
|
82
|
+
#
|
|
83
|
+
# Sends `tool_removal` blocks with the next request. The tools stop being run straight away,
|
|
84
|
+
# so a call to one gets the "not found" error result. Needs the `inline-tools-2026-09-15` beta.
|
|
85
|
+
#
|
|
86
|
+
# @param tools [Array<Anthropic::Helpers::Tools::BaseTool, String, Symbol>] the tools, or their names
|
|
87
|
+
def remove_tools(*tools)
|
|
88
|
+
tools.each do |tool|
|
|
89
|
+
name =
|
|
90
|
+
case tool
|
|
91
|
+
in Anthropic::Helpers::Tools::BaseTool
|
|
92
|
+
Anthropic::Helpers::Messages.tool_api_name(tool)
|
|
93
|
+
in String | Symbol
|
|
94
|
+
tool.to_s
|
|
95
|
+
end
|
|
96
|
+
@tool_overrides.store(name, nil)
|
|
97
|
+
@pending_tool_changes << {type: :tool_removal, tool: {type: :tool_reference, name:}}
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Compact the conversation before the model's next turn. Once the current turn has finished,
|
|
102
|
+
# including any tool calls, the runner asks the API for a summary and replaces its messages with
|
|
103
|
+
# the compaction response, which you get like any other message. Requires the
|
|
104
|
+
# `compact-2026-09-04` beta.
|
|
105
|
+
#
|
|
106
|
+
# @param compaction [Anthropic::Models::Beta::BetaCompactionConfig, Hash{Symbol=>Object}, nil]
|
|
107
|
+
# the same config `messages.create(compaction:)` takes, `{type: :summarize}` when omitted
|
|
108
|
+
#
|
|
109
|
+
# @raise [ArgumentError] if `context_management` has a compaction edit
|
|
110
|
+
#
|
|
111
|
+
# @return [void]
|
|
112
|
+
def compact_before_next_turn(compaction = nil)
|
|
113
|
+
return unless @compaction_phase.nil?
|
|
114
|
+
|
|
115
|
+
check_can_compact!(params)
|
|
116
|
+
@pending_compaction = compaction || {type: :summarize}
|
|
117
|
+
end
|
|
118
|
+
|
|
42
119
|
# @return [Array<Anthropic::Beta::BetaMessageParam>]
|
|
43
120
|
private def current_messages = params&.[](:messages).to_a
|
|
44
121
|
|
|
45
122
|
# @return [Anthropic::Models::BetaMessage, nil]
|
|
46
123
|
def next_message
|
|
47
124
|
message = nil
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
[true, message]
|
|
52
|
-
end
|
|
125
|
+
fold do
|
|
126
|
+
message = @client.beta.messages.create(with_helper_header(_1, StainlessHelperHeader::BETA_TOOL_RUNNER))
|
|
127
|
+
[true, message]
|
|
53
128
|
end
|
|
54
129
|
message
|
|
55
130
|
end
|
|
@@ -93,13 +168,25 @@ module Anthropic
|
|
|
93
168
|
#
|
|
94
169
|
# @yieldparam [Array(Boolean, Anthropic::Models::Beta::MessageCreateParams)]
|
|
95
170
|
private def fold(&blk)
|
|
96
|
-
|
|
171
|
+
@compaction_phase = nil if @compaction_phase == :handling
|
|
172
|
+
return nil if finished? && @pending_compaction.nil?
|
|
97
173
|
|
|
174
|
+
brk = false
|
|
98
175
|
# rubocop:disable Metrics/BlockLength
|
|
99
176
|
# rubocop:disable Style/CaseEquality
|
|
100
177
|
loop do
|
|
178
|
+
break if finished?
|
|
101
179
|
return if @max_iterations && @iteration_count >= @max_iterations
|
|
102
180
|
|
|
181
|
+
send_pending_tool_changes
|
|
182
|
+
|
|
183
|
+
if @pending_compaction && !turn_paused?
|
|
184
|
+
brk = compact(@pending_compaction, &blk)
|
|
185
|
+
break if brk
|
|
186
|
+
next
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
reject_compaction_param!(params)
|
|
103
190
|
tools = params[:tools].to_a.grep(Anthropic::Helpers::Tools::BaseTool)
|
|
104
191
|
messages = current_messages
|
|
105
192
|
brk, response = blk.call(params)
|
|
@@ -121,21 +208,27 @@ module Anthropic
|
|
|
121
208
|
break
|
|
122
209
|
end
|
|
123
210
|
|
|
124
|
-
tool_uses =
|
|
125
|
-
next_step == :run_tools ? response.content.grep(Anthropic::Beta::BetaToolUseBlock) : []
|
|
211
|
+
tool_uses = next_step == :run_tools ? client_tool_uses(response) : []
|
|
126
212
|
|
|
127
213
|
# A `tool_removal` block only hints the model, so a call to a withdrawn tool can still
|
|
128
214
|
# arrive; a name missing from this set routes down the same "not found" path as an
|
|
129
215
|
# undeclared tool.
|
|
130
|
-
available = available_tool_names(tools,
|
|
216
|
+
available = available_tool_names([*tools, *@tool_overrides.values.compact])
|
|
131
217
|
|
|
132
218
|
mapped =
|
|
133
219
|
tool_uses.map do |tool_use|
|
|
134
220
|
resp = {type: :tool_result, tool_use_id: tool_use.id}
|
|
135
221
|
if available.include?(tool_use.name) &&
|
|
136
|
-
(tool =
|
|
222
|
+
(tool = @tool_overrides.fetch(tool_use.name) do
|
|
223
|
+
tools.find do
|
|
224
|
+
_1.class.model === tool_use.parsed && Anthropic::Helpers::Messages.tool_api_name(_1) == tool_use.name
|
|
225
|
+
end
|
|
226
|
+
end)
|
|
137
227
|
begin
|
|
138
|
-
|
|
228
|
+
# `parsed` was read against `params[:tools]`, which an added tool is not in.
|
|
229
|
+
input = tool_use.parsed
|
|
230
|
+
input = Anthropic::Internal::Type::Converter.coerce(tool, tool_use.input) if @tool_overrides.key?(tool_use.name)
|
|
231
|
+
raw = tool.call(input)
|
|
139
232
|
is_error = false
|
|
140
233
|
rescue StandardError => e
|
|
141
234
|
is_error = true
|
|
@@ -154,20 +247,7 @@ module Anthropic
|
|
|
154
247
|
break
|
|
155
248
|
end
|
|
156
249
|
|
|
157
|
-
|
|
158
|
-
case _1
|
|
159
|
-
in Anthropic::Beta::BetaToolUseBlock
|
|
160
|
-
# `parsed` is only set for calls to a declared tool; any other call (e.g. to an
|
|
161
|
-
# unregistered tool) must replay the `input` the API sent, never a null.
|
|
162
|
-
input = _1.parsed.nil? ? _1.input : _1.parsed
|
|
163
|
-
raw = {**_1, input:}.except(:parsed)
|
|
164
|
-
Anthropic::Internal::Type::Converter.dump(Anthropic::Beta::BetaToolUseBlock, raw)
|
|
165
|
-
else
|
|
166
|
-
_1
|
|
167
|
-
end
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
messages << {role: :assistant, content:}
|
|
250
|
+
messages << assistant_turn(response)
|
|
171
251
|
messages << {role: :user, content: mapped} unless mapped.empty?
|
|
172
252
|
adopt_container(response)
|
|
173
253
|
|
|
@@ -177,6 +257,199 @@ module Anthropic
|
|
|
177
257
|
end
|
|
178
258
|
# rubocop:enable Style/CaseEquality
|
|
179
259
|
# rubocop:enable Metrics/BlockLength
|
|
260
|
+
|
|
261
|
+
compact_after_final_turn(&blk) if finished? && !brk
|
|
262
|
+
nil
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
# @api private
|
|
266
|
+
#
|
|
267
|
+
# @param response [Anthropic::Models::BetaMessage]
|
|
268
|
+
#
|
|
269
|
+
# @return [Hash{Symbol=>Object}]
|
|
270
|
+
private def assistant_turn(response)
|
|
271
|
+
content = response.content.map do
|
|
272
|
+
case _1
|
|
273
|
+
# The class alone doesn't make a block a tool call, see `#client_tool_uses`.
|
|
274
|
+
in Anthropic::Beta::BetaToolUseBlock if block_type(_1) == :tool_use
|
|
275
|
+
# `parsed` is only set for calls to a declared tool; any other call (e.g. to an
|
|
276
|
+
# unregistered tool) must replay the `input` the API sent, never a null. So must a
|
|
277
|
+
# tool `add_tools` / `remove_tools` changed: `parsed` came from `params[:tools]`.
|
|
278
|
+
input = _1.parsed.nil? || @tool_overrides.key?(_1.name) ? _1.input : _1.parsed
|
|
279
|
+
raw = {**_1, input:}.except(:parsed)
|
|
280
|
+
Anthropic::Internal::Type::Converter.dump(Anthropic::Beta::BetaToolUseBlock, raw)
|
|
281
|
+
else
|
|
282
|
+
_1
|
|
283
|
+
end
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
{role: :assistant, content:}
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
# @api private
|
|
290
|
+
#
|
|
291
|
+
# A block of a type this SDK version doesn't know is coerced to the closest model, which can
|
|
292
|
+
# be `BetaToolUseBlock`, so the class alone doesn't make a block a tool call.
|
|
293
|
+
#
|
|
294
|
+
# @param response [Anthropic::Models::BetaMessage]
|
|
295
|
+
#
|
|
296
|
+
# @return [Array<Anthropic::Beta::BetaToolUseBlock>]
|
|
297
|
+
private def client_tool_uses(response)
|
|
298
|
+
response.content.grep(Anthropic::Beta::BetaToolUseBlock).select { block_type(_1) == :tool_use }
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
# @api private
|
|
302
|
+
#
|
|
303
|
+
# @param block [Anthropic::Models::Beta::BetaContentBlock, Hash{Symbol=>Object}]
|
|
304
|
+
#
|
|
305
|
+
# @return [Symbol, nil]
|
|
306
|
+
private def block_type(block) = read_field(block, :type)&.to_sym
|
|
307
|
+
|
|
308
|
+
# @api private
|
|
309
|
+
#
|
|
310
|
+
# @param params [Anthropic::Models::Beta::MessageCreateParams]
|
|
311
|
+
private def reject_compaction_param!(params)
|
|
312
|
+
return if params[:compaction].nil?
|
|
313
|
+
|
|
314
|
+
raise ArgumentError.new(
|
|
315
|
+
"`compaction` cannot be set on a tool runner: every request in the loop would compact again. " \
|
|
316
|
+
"Call `#compact_before_next_turn` when the conversation should be compacted instead."
|
|
317
|
+
)
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
# @api private
|
|
321
|
+
#
|
|
322
|
+
# @param params [Anthropic::Models::Beta::MessageCreateParams]
|
|
323
|
+
private def check_can_compact!(params)
|
|
324
|
+
# The compaction request is sent without `context_management`, so the API can't reject this
|
|
325
|
+
# combination there: it would run and bill the compaction, then reject the next request,
|
|
326
|
+
# where the compaction response and the compaction edit meet.
|
|
327
|
+
edits = read_field(params[:context_management], :edits)
|
|
328
|
+
return unless Array(edits).any? { read_field(_1, :type).to_s.start_with?("compact_") }
|
|
329
|
+
|
|
330
|
+
raise ArgumentError.new(
|
|
331
|
+
"`#compact_before_next_turn` can't be used while `context_management` has a compaction edit, " \
|
|
332
|
+
"because the API doesn't accept a compaction block together with one. Remove the edit first."
|
|
333
|
+
)
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
# @api private
|
|
337
|
+
#
|
|
338
|
+
# The API can't compact a conversation that ends mid-turn, so a paused turn is resumed first.
|
|
339
|
+
#
|
|
340
|
+
# @return [Boolean]
|
|
341
|
+
private def turn_paused?
|
|
342
|
+
!@last_response.nil? && determine_next_step_from_stop_reason(@last_response.stop_reason) == :resume
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
# @api private
|
|
346
|
+
#
|
|
347
|
+
# @param compaction [Anthropic::Models::Beta::BetaCompactionConfig, Hash{Symbol=>Object}]
|
|
348
|
+
#
|
|
349
|
+
# @return [Boolean] whether the caller asked for a single message
|
|
350
|
+
private def compact(compaction, &blk)
|
|
351
|
+
check_can_compact!(params)
|
|
352
|
+
request = {**without_compaction_incompatible_params(params), compaction:}
|
|
353
|
+
@pending_compaction = nil
|
|
354
|
+
@compaction_phase = :in_flight
|
|
355
|
+
|
|
356
|
+
brk, response = blk.call(request)
|
|
357
|
+
|
|
358
|
+
if response.content.any? { block_type(_1) == :compaction && !read_field(_1, :content).to_s.empty? }
|
|
359
|
+
keep_removals_from_history
|
|
360
|
+
# The response has to be sent back as it came, first, replacing the messages it summarizes.
|
|
361
|
+
@params = {**params.to_h, messages: [assistant_turn(response)]}
|
|
362
|
+
else
|
|
363
|
+
warn("[anthropic-ruby] Compaction produced no summary; keeping the conversation as it is.")
|
|
364
|
+
end
|
|
365
|
+
# `#next_message` hands the response over only now; its caller is looking at it until the
|
|
366
|
+
# runner is next advanced, which is when `#fold` clears this.
|
|
367
|
+
@compaction_phase = :handling if brk
|
|
368
|
+
brk
|
|
369
|
+
ensure
|
|
370
|
+
@compaction_phase = nil if @compaction_phase == :in_flight
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
# @api private
|
|
374
|
+
#
|
|
375
|
+
# A compaction request returns only the compaction block, never a reply, so the API rejects
|
|
376
|
+
# the params that only shape a reply. The runner's later requests keep them.
|
|
377
|
+
#
|
|
378
|
+
# @param params [Anthropic::Models::Beta::MessageCreateParams, Hash{Symbol=>Object}]
|
|
379
|
+
#
|
|
380
|
+
# @return [Hash{Symbol=>Object}]
|
|
381
|
+
private def without_compaction_incompatible_params(params)
|
|
382
|
+
kept = params.to_h.except(:context_management, :stop_sequences, :output_format)
|
|
383
|
+
forced_tool = [:any, :tool].include?(read_field(kept[:tool_choice], :type)&.to_sym)
|
|
384
|
+
kept = without_output_format(forced_tool ? kept.except(:tool_choice) : kept)
|
|
385
|
+
return kept unless kept[:fallbacks].is_a?(Array)
|
|
386
|
+
|
|
387
|
+
fallbacks = kept[:fallbacks].map do
|
|
388
|
+
fallback = Anthropic::Internal::Type::Converter.dump(Anthropic::Beta::BetaFallbackParam, _1)
|
|
389
|
+
without_output_format(fallback)
|
|
390
|
+
end
|
|
391
|
+
{**kept, fallbacks:}
|
|
392
|
+
end
|
|
393
|
+
|
|
394
|
+
# @api private
|
|
395
|
+
#
|
|
396
|
+
# @param params [Hash{Symbol=>Object}] a request's params, or one of its fallbacks'
|
|
397
|
+
#
|
|
398
|
+
# @return [Hash{Symbol=>Object}]
|
|
399
|
+
private def without_output_format(params)
|
|
400
|
+
# Read in its wire form: a typed `BetaOutputConfig` holds `format` under its Ruby name, `format_`.
|
|
401
|
+
dumped = Anthropic::Internal::Type::Converter.dump(
|
|
402
|
+
Anthropic::Beta::BetaOutputConfig,
|
|
403
|
+
params[:output_config]
|
|
404
|
+
)
|
|
405
|
+
output_config = dumped.to_h.except(:format)
|
|
406
|
+
output_config.empty? ? params.except(:output_config) : {**params, output_config:}
|
|
407
|
+
end
|
|
408
|
+
|
|
409
|
+
# @api private
|
|
410
|
+
private def compact_after_final_turn(&blk)
|
|
411
|
+
return if @pending_compaction.nil?
|
|
412
|
+
|
|
413
|
+
# The loop never adds the final turn to the history, so it is added here for the compaction
|
|
414
|
+
# to cover it, and forgotten so that a later compaction doesn't add it again.
|
|
415
|
+
unless @last_response.nil?
|
|
416
|
+
if client_tool_uses(@last_response).any?
|
|
417
|
+
# A turn that was cut short can end with tool calls that are never run, and the API
|
|
418
|
+
# can't compact a conversation whose last turn has an unanswered tool call.
|
|
419
|
+
warn(
|
|
420
|
+
"[anthropic-ruby] The pending compaction was skipped because the last turn " \
|
|
421
|
+
"(stop_reason: #{@last_response.stop_reason.inspect}) ended with tool calls that " \
|
|
422
|
+
"were not run. Call `#compact_before_next_turn` again if you continue the conversation."
|
|
423
|
+
)
|
|
424
|
+
@pending_compaction = nil
|
|
425
|
+
return
|
|
426
|
+
end
|
|
427
|
+
|
|
428
|
+
current_messages << assistant_turn(@last_response)
|
|
429
|
+
@last_response = nil
|
|
430
|
+
end
|
|
431
|
+
|
|
432
|
+
compact(@pending_compaction, &blk)
|
|
433
|
+
end
|
|
434
|
+
|
|
435
|
+
# @api private
|
|
436
|
+
#
|
|
437
|
+
# A paused turn is sent back as it came, so nothing may follow it.
|
|
438
|
+
private def send_pending_tool_changes
|
|
439
|
+
return if @pending_tool_changes.empty? || @last_response&.stop_reason == :pause_turn
|
|
440
|
+
|
|
441
|
+
current_messages << {role: :system, content: @pending_tool_changes}
|
|
442
|
+
@pending_tool_changes = []
|
|
443
|
+
end
|
|
444
|
+
|
|
445
|
+
# @api private
|
|
446
|
+
#
|
|
447
|
+
# A compaction response replaces the history, `tool_removal` blocks included, so what the
|
|
448
|
+
# history took away is taken out of the overrides first.
|
|
449
|
+
private def keep_removals_from_history
|
|
450
|
+
runnable = [*params[:tools].to_a.grep(Anthropic::Helpers::Tools::BaseTool), *@tool_overrides.values.compact]
|
|
451
|
+
names = runnable.map { Anthropic::Helpers::Messages.tool_api_name(_1) }
|
|
452
|
+
(names - available_tool_names(runnable).to_a).each { @tool_overrides.store(_1, nil) }
|
|
180
453
|
end
|
|
181
454
|
|
|
182
455
|
# @api private
|
|
@@ -219,16 +492,15 @@ module Anthropic
|
|
|
219
492
|
#
|
|
220
493
|
# Replays `tool_removal` / `tool_addition` blocks from `role: :system` messages to
|
|
221
494
|
# find which tool names are still offered to the model. MCP references are
|
|
222
|
-
# server-executed and never dispatched here, so they are ignored.
|
|
495
|
+
# server-executed and never dispatched here, so they are ignored. The overrides already
|
|
496
|
+
# hold the changes waiting to be sent, so those count as the history's last message.
|
|
223
497
|
#
|
|
224
498
|
# @param tools [Array<Anthropic::Helpers::Tools::BaseTool>]
|
|
225
499
|
#
|
|
226
|
-
# @param messages [Array<Anthropic::Beta::BetaMessageParam, Hash{Symbol=>Object}>]
|
|
227
|
-
#
|
|
228
500
|
# @return [Set<String>]
|
|
229
|
-
private def available_tool_names(tools
|
|
501
|
+
private def available_tool_names(tools)
|
|
230
502
|
available = Set.new(tools.map { Anthropic::Helpers::Messages.tool_api_name(_1) })
|
|
231
|
-
|
|
503
|
+
[*current_messages, {role: :system, content: @pending_tool_changes}].each do |message|
|
|
232
504
|
next unless read_field(message, :role)&.to_sym == :system
|
|
233
505
|
|
|
234
506
|
Array(read_field(message, :content)).each { apply_tool_change(_1, available) }
|
|
@@ -244,10 +516,10 @@ module Anthropic
|
|
|
244
516
|
private def apply_tool_change(block, available)
|
|
245
517
|
case read_field(block, :type)&.to_sym
|
|
246
518
|
in :tool_removal
|
|
247
|
-
name =
|
|
519
|
+
name = changed_tool_name(read_field(block, :tool))
|
|
248
520
|
available.delete(name) unless name.nil?
|
|
249
521
|
in :tool_addition
|
|
250
|
-
name =
|
|
522
|
+
name = changed_tool_name(read_field(block, :tool))
|
|
251
523
|
available.add(name) unless name.nil?
|
|
252
524
|
else
|
|
253
525
|
nil # non tool_removal / tool_addition blocks leave the set untouched
|
|
@@ -256,13 +528,16 @@ module Anthropic
|
|
|
256
528
|
|
|
257
529
|
# @api private
|
|
258
530
|
#
|
|
259
|
-
# @param
|
|
531
|
+
# @param tool [Anthropic::Beta::BetaToolChangeToolReference, Anthropic::Beta::BetaToolChangeToolDefinitionParam, Hash{Symbol=>Object}, nil]
|
|
260
532
|
#
|
|
261
533
|
# @return [String, nil]
|
|
262
|
-
private def
|
|
263
|
-
case read_field(
|
|
534
|
+
private def changed_tool_name(tool)
|
|
535
|
+
case read_field(tool, :type)&.to_sym
|
|
264
536
|
in :tool_reference
|
|
265
|
-
read_field(
|
|
537
|
+
read_field(tool, :name).to_s
|
|
538
|
+
in :tool_definition
|
|
539
|
+
# Not every `tools[]` entry has a name (e.g. `mcp_toolset`); those never run here.
|
|
540
|
+
read_field(read_field(tool, :definition), :name)&.to_s
|
|
266
541
|
else
|
|
267
542
|
nil # `mcp_*` references run server-side; unknown types ignored (forward compatibility)
|
|
268
543
|
end
|
|
@@ -403,12 +678,17 @@ module Anthropic
|
|
|
403
678
|
def initialize(client, params:, max_iterations: nil, compaction_control: nil)
|
|
404
679
|
@client = client
|
|
405
680
|
@params = params.to_h
|
|
681
|
+
reject_compaction_param!(@params)
|
|
406
682
|
@finished = false
|
|
407
683
|
@max_iterations = max_iterations
|
|
408
684
|
@iteration_count = 0
|
|
409
685
|
@compaction_control = compaction_control
|
|
410
686
|
@compaction_warned = false
|
|
411
687
|
@last_response = nil
|
|
688
|
+
@pending_tool_changes = []
|
|
689
|
+
@tool_overrides = {}
|
|
690
|
+
@pending_compaction = nil
|
|
691
|
+
@compaction_phase = nil
|
|
412
692
|
end
|
|
413
693
|
|
|
414
694
|
private def with_helper_header(params, helper)
|