ibm-watsonx-orchestrate 1.0.0__py3-none-any.whl

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.
Files changed (89) hide show
  1. ibm_watsonx_orchestrate/__init__.py +28 -0
  2. ibm_watsonx_orchestrate/agent_builder/__init__.py +0 -0
  3. ibm_watsonx_orchestrate/agent_builder/agents/__init__.py +5 -0
  4. ibm_watsonx_orchestrate/agent_builder/agents/agent.py +27 -0
  5. ibm_watsonx_orchestrate/agent_builder/agents/assistant_agent.py +28 -0
  6. ibm_watsonx_orchestrate/agent_builder/agents/external_agent.py +28 -0
  7. ibm_watsonx_orchestrate/agent_builder/agents/types.py +204 -0
  8. ibm_watsonx_orchestrate/agent_builder/connections/__init__.py +27 -0
  9. ibm_watsonx_orchestrate/agent_builder/connections/connections.py +123 -0
  10. ibm_watsonx_orchestrate/agent_builder/connections/types.py +260 -0
  11. ibm_watsonx_orchestrate/agent_builder/knowledge_bases/knowledge_base.py +27 -0
  12. ibm_watsonx_orchestrate/agent_builder/knowledge_bases/knowledge_base_requests.py +59 -0
  13. ibm_watsonx_orchestrate/agent_builder/knowledge_bases/types.py +243 -0
  14. ibm_watsonx_orchestrate/agent_builder/tools/__init__.py +4 -0
  15. ibm_watsonx_orchestrate/agent_builder/tools/base_tool.py +36 -0
  16. ibm_watsonx_orchestrate/agent_builder/tools/openapi_tool.py +332 -0
  17. ibm_watsonx_orchestrate/agent_builder/tools/python_tool.py +195 -0
  18. ibm_watsonx_orchestrate/agent_builder/tools/types.py +162 -0
  19. ibm_watsonx_orchestrate/agent_builder/utils/__init__.py +0 -0
  20. ibm_watsonx_orchestrate/agent_builder/utils/pydantic_utils.py +149 -0
  21. ibm_watsonx_orchestrate/cli/__init__.py +0 -0
  22. ibm_watsonx_orchestrate/cli/commands/__init__.py +0 -0
  23. ibm_watsonx_orchestrate/cli/commands/agents/agents_command.py +192 -0
  24. ibm_watsonx_orchestrate/cli/commands/agents/agents_controller.py +660 -0
  25. ibm_watsonx_orchestrate/cli/commands/channels/channels_command.py +15 -0
  26. ibm_watsonx_orchestrate/cli/commands/channels/channels_controller.py +16 -0
  27. ibm_watsonx_orchestrate/cli/commands/channels/types.py +15 -0
  28. ibm_watsonx_orchestrate/cli/commands/channels/webchat/channels_webchat_command.py +32 -0
  29. ibm_watsonx_orchestrate/cli/commands/channels/webchat/channels_webchat_controller.py +141 -0
  30. ibm_watsonx_orchestrate/cli/commands/chat/chat_command.py +43 -0
  31. ibm_watsonx_orchestrate/cli/commands/connections/connections_command.py +307 -0
  32. ibm_watsonx_orchestrate/cli/commands/connections/connections_controller.py +517 -0
  33. ibm_watsonx_orchestrate/cli/commands/environment/environment_command.py +78 -0
  34. ibm_watsonx_orchestrate/cli/commands/environment/environment_controller.py +189 -0
  35. ibm_watsonx_orchestrate/cli/commands/environment/types.py +9 -0
  36. ibm_watsonx_orchestrate/cli/commands/knowledge_bases/knowledge_bases_command.py +79 -0
  37. ibm_watsonx_orchestrate/cli/commands/knowledge_bases/knowledge_bases_controller.py +201 -0
  38. ibm_watsonx_orchestrate/cli/commands/login/login_command.py +17 -0
  39. ibm_watsonx_orchestrate/cli/commands/models/models_command.py +128 -0
  40. ibm_watsonx_orchestrate/cli/commands/server/server_command.py +623 -0
  41. ibm_watsonx_orchestrate/cli/commands/settings/__init__.py +0 -0
  42. ibm_watsonx_orchestrate/cli/commands/settings/observability/__init__.py +0 -0
  43. ibm_watsonx_orchestrate/cli/commands/settings/observability/langfuse/__init__.py +0 -0
  44. ibm_watsonx_orchestrate/cli/commands/settings/observability/langfuse/langfuse_command.py +175 -0
  45. ibm_watsonx_orchestrate/cli/commands/settings/observability/observability_command.py +11 -0
  46. ibm_watsonx_orchestrate/cli/commands/settings/settings_command.py +10 -0
  47. ibm_watsonx_orchestrate/cli/commands/tools/tools_command.py +85 -0
  48. ibm_watsonx_orchestrate/cli/commands/tools/tools_controller.py +564 -0
  49. ibm_watsonx_orchestrate/cli/commands/tools/types.py +10 -0
  50. ibm_watsonx_orchestrate/cli/config.py +226 -0
  51. ibm_watsonx_orchestrate/cli/main.py +32 -0
  52. ibm_watsonx_orchestrate/client/__init__.py +0 -0
  53. ibm_watsonx_orchestrate/client/agents/agent_client.py +46 -0
  54. ibm_watsonx_orchestrate/client/agents/assistant_agent_client.py +38 -0
  55. ibm_watsonx_orchestrate/client/agents/external_agent_client.py +38 -0
  56. ibm_watsonx_orchestrate/client/analytics/__init__.py +0 -0
  57. ibm_watsonx_orchestrate/client/analytics/llm/__init__.py +0 -0
  58. ibm_watsonx_orchestrate/client/analytics/llm/analytics_llm_client.py +50 -0
  59. ibm_watsonx_orchestrate/client/base_api_client.py +113 -0
  60. ibm_watsonx_orchestrate/client/base_service_instance.py +10 -0
  61. ibm_watsonx_orchestrate/client/client.py +71 -0
  62. ibm_watsonx_orchestrate/client/client_errors.py +359 -0
  63. ibm_watsonx_orchestrate/client/connections/__init__.py +10 -0
  64. ibm_watsonx_orchestrate/client/connections/connections_client.py +162 -0
  65. ibm_watsonx_orchestrate/client/connections/utils.py +27 -0
  66. ibm_watsonx_orchestrate/client/credentials.py +123 -0
  67. ibm_watsonx_orchestrate/client/knowledge_bases/knowledge_base_client.py +46 -0
  68. ibm_watsonx_orchestrate/client/local_service_instance.py +91 -0
  69. ibm_watsonx_orchestrate/client/service_instance.py +73 -0
  70. ibm_watsonx_orchestrate/client/tools/tool_client.py +41 -0
  71. ibm_watsonx_orchestrate/client/utils.py +95 -0
  72. ibm_watsonx_orchestrate/docker/compose-lite.yml +595 -0
  73. ibm_watsonx_orchestrate/docker/default.env +125 -0
  74. ibm_watsonx_orchestrate/docker/sdk/ibm_watsonx_orchestrate-0.6.0-py3-none-any.whl +0 -0
  75. ibm_watsonx_orchestrate/docker/sdk/ibm_watsonx_orchestrate-0.6.0.tar.gz +0 -0
  76. ibm_watsonx_orchestrate/docker/start-up.sh +61 -0
  77. ibm_watsonx_orchestrate/docker/tempus/common-config.yaml +1 -0
  78. ibm_watsonx_orchestrate/run/__init__.py +0 -0
  79. ibm_watsonx_orchestrate/run/connections.py +40 -0
  80. ibm_watsonx_orchestrate/utils/__init__.py +0 -0
  81. ibm_watsonx_orchestrate/utils/logging/__init__.py +0 -0
  82. ibm_watsonx_orchestrate/utils/logging/logger.py +26 -0
  83. ibm_watsonx_orchestrate/utils/logging/logging.yaml +18 -0
  84. ibm_watsonx_orchestrate/utils/utils.py +15 -0
  85. ibm_watsonx_orchestrate-1.0.0.dist-info/METADATA +34 -0
  86. ibm_watsonx_orchestrate-1.0.0.dist-info/RECORD +89 -0
  87. ibm_watsonx_orchestrate-1.0.0.dist-info/WHEEL +4 -0
  88. ibm_watsonx_orchestrate-1.0.0.dist-info/entry_points.txt +2 -0
  89. ibm_watsonx_orchestrate-1.0.0.dist-info/licenses/LICENSE +22 -0
@@ -0,0 +1,149 @@
1
+ import json
2
+ from pathlib import Path
3
+ from typing import Any, Dict, Type, Literal
4
+
5
+ import jsonschema
6
+ from pydantic import BaseModel
7
+ from pydantic.json_schema import DEFAULT_REF_TEMPLATE, GenerateJsonSchema, JsonSchemaMode
8
+ from pydantic.main import IncEx
9
+ from typing_extensions import Self
10
+
11
+ from ibm_watsonx_orchestrate.agent_builder.tools import ToolRequestBody, ToolResponseBody, JsonSchemaObject
12
+
13
+
14
+ def generate_schema_only_base_model(schema: ToolRequestBody | ToolResponseBody | JsonSchemaObject) -> Type[BaseModel]:
15
+ class SchemaOnlyBaseModel(BaseModel):
16
+ __primitive__: Any
17
+ model_config = {
18
+ 'extra': 'allow'
19
+ }
20
+ """
21
+ The purpose of a SchemaOnlyBaseModel is to pass along the json schema represented by schema
22
+ to a langchain tool's arg_schema
23
+ :arg schema The json schema to emulate
24
+ :returns a fake BaseModel that only returns a json schema
25
+ """
26
+
27
+ def __init__(self, /, *args, **kwargs: Any) -> None:
28
+ if schema.type == 'object':
29
+ super().__init__(**kwargs)
30
+ for name, value in kwargs.items():
31
+ setattr(self, name, value)
32
+ else:
33
+ kwargs={}
34
+ kwargs['__primitive__'] = args[0]
35
+ super().__init__(**kwargs)
36
+ setattr(self, '__primitive__', args[0])
37
+
38
+ @classmethod
39
+ def model_json_schema(cls, by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE,
40
+ schema_generator: type[GenerateJsonSchema] = GenerateJsonSchema,
41
+ mode: JsonSchemaMode = 'validation') -> dict[str, Any]:
42
+ return schema.model_dump(exclude_unset=True, exclude_none=True)
43
+
44
+ @classmethod
45
+ def schema(cls, by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE) -> Dict[str, Any]:
46
+ return schema.model_dump(exclude_unset=True, exclude_none=True)
47
+
48
+ @classmethod
49
+ def schema_json(cls, *, by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE,
50
+ **dumps_kwargs: Any) -> str:
51
+ return schema.model_dump_json(exclude_unset=True, exclude_none=True)
52
+
53
+ @classmethod
54
+ def model_validate_json(cls, json_data: str | bytes | bytearray, *, strict: bool | None = None,
55
+ context: Any | None = None) -> Self:
56
+ obj = json.loads(json_data)
57
+ jsonschema.validate(obj, schema=schema.model_dump(exclude_unset=True))
58
+ if schema.type == 'object':
59
+ return SchemaOnlyBaseModel(**obj)
60
+ else:
61
+ return SchemaOnlyBaseModel(obj)
62
+
63
+ @classmethod
64
+ def model_validate(cls, obj: Any, *, strict: bool | None = None, from_attributes: bool | None = None,
65
+ context: Any | None = None) -> Self:
66
+ jsonschema.validate(obj, schema=schema.model_dump(exclude_unset=True))
67
+ if schema.type == 'object':
68
+ return SchemaOnlyBaseModel(**obj)
69
+ else:
70
+ return SchemaOnlyBaseModel(obj)
71
+
72
+ @classmethod
73
+ def model_validate_strings(cls, obj: Any, *, strict: bool | None = None, context: Any | None = None) -> Self:
74
+ raise NotImplementedError('unimplemented for SchemaOnlyBaseModel')
75
+
76
+ @classmethod
77
+ def validate(cls, value: Any) -> Self:
78
+ jsonschema.validate(value, schema=schema.model_dump(exclude_unset=True))
79
+ return SchemaOnlyBaseModel(**value)
80
+
81
+ @classmethod
82
+ def model_construct(cls, _fields_set: set[str] | None = None, **values: Any) -> Self:
83
+ raise NotImplementedError('unimplemented for SchemaOnlyBaseModel')
84
+
85
+ @classmethod
86
+ def model_parametrized_name(cls, params: tuple[type[Any], ...]) -> str:
87
+ raise NotImplementedError('unimplemented for SchemaOnlyBaseModel')
88
+
89
+ @classmethod
90
+ def model_rebuild(cls, *, force: bool = False, raise_errors: bool = True, _parent_namespace_depth: int = 2,
91
+ _types_namespace: Any = None) -> bool | None:
92
+ raise NotImplementedError('unimplemented for SchemaOnlyBaseModel')
93
+
94
+ @classmethod
95
+ def parse_obj(cls, obj: Any) -> Self:
96
+ raise NotImplementedError('unimplemented for SchemaOnlyBaseModel')
97
+
98
+ @classmethod
99
+ def parse_raw(cls, b: str | bytes, *, content_type: str | None = None, encoding: str = 'utf8',
100
+ proto: Any | None = None, allow_pickle: bool = False) -> Self:
101
+ raise NotImplementedError('unimplemented for SchemaOnlyBaseModel')
102
+
103
+ @classmethod
104
+ def parse_file(cls, path: str | Path, *, content_type: str | None = None, encoding: str = 'utf8',
105
+ proto: Any | None = None, allow_pickle: bool = False) -> Self:
106
+ raise NotImplementedError('unimplemented for SchemaOnlyBaseModel')
107
+
108
+ @classmethod
109
+ def from_orm(cls, obj: Any) -> Self:
110
+ raise NotImplementedError('unimplemented for SchemaOnlyBaseModel')
111
+
112
+ @classmethod
113
+ def construct(cls, _fields_set: set[str] | None = None, **values: Any) -> Self:
114
+ raise NotImplementedError('unimplemented for SchemaOnlyBaseModel')
115
+
116
+ @classmethod
117
+ def update_forward_refs(cls, **localns: Any) -> None:
118
+ raise NotImplementedError('unimplemented for SchemaOnlyBaseModel')
119
+
120
+ def model_dump(self, *, mode: Literal['json', 'python'] | str = 'python', include: IncEx | None = None,
121
+ exclude: IncEx | None = None, context: Any | None = None, by_alias: bool = False,
122
+ exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False,
123
+ round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True,
124
+ serialize_as_any: bool = False) -> dict[str, Any]:
125
+ primitive = getattr(self, '__primitive__', None)
126
+ if primitive is not None:
127
+ return primitive
128
+ else:
129
+ return super().model_dump(mode=mode, include=include, exclude=exclude, context=context, by_alias=by_alias,
130
+ exclude_unset=exclude_unset, exclude_defaults=exclude_defaults,
131
+ exclude_none=exclude_none, round_trip=round_trip, warnings=warnings,
132
+ serialize_as_any=serialize_as_any)
133
+
134
+ def model_dump_json(self, *, indent: int | None = None, include: IncEx | None = None,
135
+ exclude: IncEx | None = None, context: Any | None = None, by_alias: bool = False,
136
+ exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False,
137
+ round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True,
138
+ serialize_as_any: bool = False) -> str:
139
+ primitive = getattr(self, '__primitive__')
140
+ if primitive is not None:
141
+ return json.dumps(primitive)
142
+ else:
143
+ return super().model_dump_json(indent=indent, include=include, exclude=exclude, context=context,
144
+ by_alias=by_alias, exclude_unset=exclude_unset,
145
+ exclude_defaults=exclude_defaults, exclude_none=exclude_none,
146
+ round_trip=round_trip, warnings=warnings, serialize_as_any=serialize_as_any)
147
+
148
+ return SchemaOnlyBaseModel
149
+
File without changes
File without changes
@@ -0,0 +1,192 @@
1
+ import typer
2
+ from typing_extensions import Annotated, List
3
+ from ibm_watsonx_orchestrate.cli.commands.agents.agents_controller import AgentsController
4
+ from ibm_watsonx_orchestrate.agent_builder.agents.types import DEFAULT_LLM, AgentKind, AgentStyle, ExternalAgentAuthScheme, AgentProvider
5
+ import json
6
+
7
+ agents_app = typer.Typer(no_args_is_help=True)
8
+
9
+
10
+ @agents_app.command(name="import", help='Import an agent definition into the active env from a file')
11
+ def agent_import(
12
+ file: Annotated[
13
+ str,
14
+ typer.Option("--file", "-f", help="YAML file with agent definition"),
15
+ ],
16
+ app_id: Annotated[
17
+ str, typer.Option(
18
+ '--app-id', '-a',
19
+ help='The app id of the connection to associate with this external agent. An application connection represents the server authentication credentials needed to connection to this agent (for example Api Keys, Basic, Bearer or OAuth credentials).'
20
+ )
21
+ ] = None,
22
+ ):
23
+ agents_controller = AgentsController()
24
+ agent_specs = agents_controller.import_agent(file=file, app_id=app_id)
25
+ agents_controller.publish_or_update_agents(agent_specs)
26
+
27
+
28
+ @agents_app.command(name="create", help='Create and import an agent into the active env')
29
+ def agent_create(
30
+ name: Annotated[
31
+ str,
32
+ typer.Option("--name", "-n", help="Name of the agent you wish to create"),
33
+ ],
34
+ title: Annotated[
35
+ str,
36
+ typer.Option("--title", "-t", help="Title of the agent you wish to create. Only needed for External and Assistant Agents"),
37
+ ] = None,
38
+ kind: Annotated[
39
+ AgentKind,
40
+ typer.Option("--kind", "-k", help="The kind of agent you wish to create"),
41
+ ] = AgentKind.NATIVE,
42
+ api_url: Annotated[
43
+ str,
44
+ typer.Option("--api", "-a", help="External Api url your Agent will use"),
45
+ ] = None,
46
+ auth_scheme: Annotated[
47
+ ExternalAgentAuthScheme,
48
+ typer.Option("--auth-scheme", help="External Api auth schema to be used"),
49
+ ] = ExternalAgentAuthScheme.NONE,
50
+ provider: Annotated[
51
+ AgentProvider,
52
+ typer.Option("--provider", "-p", help="Agent Provider to be used.")
53
+ ] = AgentProvider.EXT_CHAT,
54
+ auth_config: Annotated[
55
+ str,
56
+ typer.Option(
57
+ "--auth-config",
58
+ help="Auth configuration to be used in JSON format (e.g., '{\"token\": \"test-api-key1\"')",
59
+ ),
60
+ ] = {},
61
+ tags: Annotated[
62
+ List[str],
63
+ typer.Option(
64
+ "--tags",
65
+ help="A list of tags for the agent. Format: --tags tag1 --tags tag2 ... Only needed for External and Assistant Agents",
66
+ ),
67
+ ] = None,
68
+ chat_params: Annotated[
69
+ str,
70
+ typer.Option(
71
+ "--chat-params",
72
+ help="Chat parameters in JSON format (e.g., '{\"stream\": true}'). Only needed for External and Assistant Agents",
73
+ ),
74
+ ] = None,
75
+ config: Annotated[
76
+ str,
77
+ typer.Option(
78
+ "--config",
79
+ help="Agent configuration in JSON format (e.g., '{\"hidden\": false, \"enable_cot\": false}')",
80
+ ),
81
+ ] = None,
82
+ nickname: Annotated[
83
+ str,
84
+ typer.Option("--nickname", help="Agent's nickname"),
85
+ ] = None,
86
+ app_id: Annotated[
87
+ str,
88
+ typer.Option("--app-id", help="Application ID for the agent"),
89
+ ] = None,
90
+ description: Annotated[
91
+ str,
92
+ typer.Option(
93
+ "--description",
94
+ help="Description of the agent",
95
+ ),
96
+ ] = None,
97
+ llm: Annotated[
98
+ str,
99
+ typer.Option(
100
+ "--llm",
101
+ help="The LLM used by the agent",
102
+ ),
103
+ ] = DEFAULT_LLM,
104
+ style: Annotated[
105
+ AgentStyle,
106
+ typer.Option("--style", help="The style of agent you wish to create"),
107
+ ] = AgentStyle.DEFAULT,
108
+ collaborators: Annotated[
109
+ List[str],
110
+ typer.Option(
111
+ "--collaborators",
112
+ help="A list of agent names you wish for the agent to be able to collaborate with. Format --colaborators agent1 --collaborators agent2 ...",
113
+ ),
114
+ ] = None,
115
+ tools: Annotated[
116
+ List[str],
117
+ typer.Option(
118
+ "--tools",
119
+ help="A list of tool names you wish for the agent to be able to utilise. Format --tools tool1 --tools agent2 ...",
120
+ ),
121
+ ] = None,
122
+ knowledge_base: Annotated[
123
+ List[str],
124
+ typer.Option(
125
+ "--knowledge-bases",
126
+ help="A list of knowlege bases names you wish for the agent to be able to utilise. Format --knowledge-bases base1 --knowledge-bases base2 ...",
127
+ ),
128
+ ] = None,
129
+ output_file: Annotated[
130
+ str,
131
+ typer.Option(
132
+ "--output",
133
+ "-o",
134
+ help="Write the agent definition out to a YAML (.yaml/.yml) file or a JSON (.json) file.",
135
+ ),
136
+ ] = None,
137
+ ):
138
+ chat_params_dict = json.loads(chat_params) if chat_params else {}
139
+ config_dict = json.loads(config) if config else {}
140
+ auth_config_dict = json.loads(auth_config) if auth_config else {}
141
+
142
+ agents_controller = AgentsController()
143
+ agent = agents_controller.generate_agent_spec(
144
+ name=name,
145
+ kind=kind,
146
+ description=description,
147
+ title=title,
148
+ api_url=api_url,
149
+ auth_scheme=auth_scheme,
150
+ auth_config=auth_config_dict,
151
+ provider=provider,
152
+ llm=llm,
153
+ style=style,
154
+ collaborators=collaborators,
155
+ tools=tools,
156
+ knowledge_base=knowledge_base,
157
+ tags=tags,
158
+ chat_params=chat_params_dict,
159
+ config=config_dict,
160
+ nickname=nickname,
161
+ app_id=app_id,
162
+ output_file=output_file,
163
+ )
164
+ agents_controller.publish_or_update_agents([agent])
165
+
166
+ @agents_app.command(name="list", help='List all agents in the active env')
167
+ def list_agents(
168
+ kind: Annotated[
169
+ AgentKind,
170
+ typer.Option("--kind", "-k", help="The kind of agent you wish to create"),
171
+ ] = None,
172
+ verbose: Annotated[
173
+ bool,
174
+ typer.Option("--verbose", "-v", help="List full details of all agents in json format"),
175
+ ] = False,
176
+ ):
177
+ agents_controller = AgentsController()
178
+ agents_controller.list_agents(kind=kind, verbose=verbose)
179
+
180
+ @agents_app.command(name="remove", help='Remove an agent from the active env')
181
+ def remove_agent(
182
+ name: Annotated[
183
+ str,
184
+ typer.Option("--name", "-n", help="Name of the agent you wish to remove"),
185
+ ],
186
+ kind: Annotated[
187
+ AgentKind,
188
+ typer.Option("--kind", "-k", help="The kind of agent you wish to remove"),
189
+ ]
190
+ ):
191
+ agents_controller = AgentsController()
192
+ agents_controller.remove_agent(name=name, kind=kind)