Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass additional fields to agent create #2272

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion flytekit/extend/backend/agent_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@
agent = AgentRegistry.get_agent(template.type, template.task_type_version)

logger.info(f"{agent.name} start creating the job")
resource_mata = await mirror_async_methods(agent.create, task_template=template, inputs=inputs)
resource_mata = await mirror_async_methods(

Check warning on line 120 in flytekit/extend/backend/agent_service.py

View check run for this annotation

Codecov / codecov/patch

flytekit/extend/backend/agent_service.py#L120

Added line #L120 was not covered by tests
agent.create,
task_template=template,
inputs=inputs,
output_prefix=request.output_prefix,
)
return CreateTaskResponse(resource_meta=resource_mata.encode())

@record_agent_metrics
Expand Down
5 changes: 4 additions & 1 deletion flytekit/extend/backend/base_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ def metadata_type(self) -> ResourceMeta:
return self._metadata_type

@abstractmethod
def create(self, task_template: TaskTemplate, inputs: Optional[LiteralMap], **kwargs) -> ResourceMeta:
def create(
self, task_template: TaskTemplate, inputs: Optional[LiteralMap], output_prefix: Optional[str], **kwargs
) -> ResourceMeta:
"""
Return a resource meta that can be used to get the status of the task.
"""
Expand Down Expand Up @@ -312,6 +314,7 @@ async def _create(
self._agent.create,
task_template=task_template,
inputs=literal_map,
output_prefix=output_prefix,
)

signal.signal(signal.SIGINT, partial(self.signal_handler, resource_meta)) # type: ignore
Expand Down
12 changes: 9 additions & 3 deletions tests/flytekit/unit/extend/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
@dataclass
class DummyMetadata(ResourceMeta):
job_id: str
output_path: typing.Optional[str] = None


class DummyAgent(AsyncAgentBase):
Expand All @@ -72,9 +73,14 @@ def __init__(self):
super().__init__(task_type_name="async_dummy", metadata_type=DummyMetadata)

async def create(
self, task_template: TaskTemplate, inputs: typing.Optional[LiteralMap] = None, **kwargs
self,
task_template: TaskTemplate,
inputs: typing.Optional[LiteralMap] = None,
output_prefix: typing.Optional[str] = None,
**kwargs,
) -> DummyMetadata:
return DummyMetadata(job_id=dummy_id)
output_path = f"{output_prefix}/{dummy_id}" if output_prefix else None
return DummyMetadata(job_id=dummy_id, output_path=output_path)

async def get(self, resource_meta: DummyMetadata, **kwargs) -> Resource:
return Resource(phase=TaskExecution.SUCCEEDED, log_links=[TaskLog(name="console", uri="localhost:3000")])
Expand Down Expand Up @@ -164,7 +170,7 @@ async def test_async_agent_service(agent):

inputs_proto = task_inputs.to_flyte_idl()
output_prefix = "/tmp"
metadata_bytes = DummyMetadata(job_id=dummy_id).encode()
metadata_bytes = DummyMetadata(job_id=dummy_id, output_path=f"{output_prefix}/{dummy_id}").encode()

tmp = get_task_template(agent.task_category.name).to_flyte_idl()
task_category = TaskCategory(name=agent.task_category.name, version=0)
Expand Down
Loading